This commit is contained in:
mahdi purHosseini
2023-12-11 10:43:30 +03:30
parent eeb68e0438
commit 92c5d633f7
2 changed files with 74 additions and 81 deletions
+8 -14
View File
@@ -40,30 +40,24 @@ class Item extends Model implements HasMedia
public function registerMediaCollections(): void
{
$this->addMediaCollection( 'main_image' )
->useFallbackUrl( config( 'media-library.wm-cdn' ) . '/images/placeholder/blog-placeholder.jpg' )
->useFallbackPath( public_path( '/images/placeholder/blog-placeholder.jpg' ) )
->singleFile();
$this->addMediaCollection('files')
->useFallbackUrl('/files/default_pastry.jpg')
->useFallbackPath(public_path('/files/default_pastry.jpg'));
}
public function registerMediaConversions( Media $media = null )
{
$crop = $media->getCustomProperty( 'crop' );
$conversion = $this->addMediaConversion( 'thumbnail' );
$conversion = ! $crop ? $conversion : $conversion->manualCrop( $crop[ 'width' ] , $crop[ 'height' ] , $crop[ 'left' ] , $crop[ 'top' ] );
$conversion->nonQueued()
->performOnCollections( 'main_image' );
$this->addMediaConversion( 'thumbnail' )
->width( 400 )
$this->addMediaConversion('thumbnail')
->width(480)
->height(640)
->nonQueued()
->performOnCollections( 'images' );
->performOnCollections('files');
}
protected static function getValidCollections(): array
{
return [
'images' ,
'files'
];
}
}