Multi-images component, refactoring medias functions
This commit is contained in:
@@ -12,12 +12,12 @@ trait Imageable
|
||||
|
||||
public function images()
|
||||
{
|
||||
return $this->hasMany('App\Models\Core\Media', 'model_id')->where('model_type', get_class($this));
|
||||
return $this->hasMany(Media::class, 'model_id')->where('model_type', get_class($this));
|
||||
}
|
||||
|
||||
public function image()
|
||||
{
|
||||
return $this->hasOne('App\Models\Core\Media', 'model_id')->where('model_type', get_class($this))->latest();
|
||||
return $this->hasOne(Media::class, 'model_id')->where('model_type', get_class($this))->latest();
|
||||
}
|
||||
|
||||
public function registerMediaConversions(Media $media = null) : void
|
||||
|
||||
@@ -35,7 +35,18 @@ trait Imageable
|
||||
|
||||
public static function getPreviewSrc($image, $with_undefined = true)
|
||||
{
|
||||
return $image ? Medias::getPreviewSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' :'');
|
||||
return $image ? Medias::getPreviewSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
|
||||
}
|
||||
|
||||
public static function getNormal($image, $with_undefined = true)
|
||||
{
|
||||
$src = self::getNormalSrc($image, $with_undefined);
|
||||
return $src ? "<img src='$src'>" : '';
|
||||
}
|
||||
|
||||
public static function getNormalSrc($image, $with_undefined = true)
|
||||
{
|
||||
return $image ? Medias::getNormalSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
|
||||
}
|
||||
|
||||
public static function getImage($image, $with_undefined = true)
|
||||
|
||||
Reference in New Issue
Block a user