How can i insert a new conversion into the existing laravel spatie medialibrary?

181 views Asked by At

i am using spatie medialibrary in laravel. I have different conversions for media collection ('product-image') like 'thumb'(7070), 'block'(100100) etc. Now i need a new conversion (152*152). How can i insert the new conversion into existing media collection without re-uploading or affecting storage path (/storage/../conversions/)? Thank you in advance.

i have no idea how to do it without re-uploading.

1

There are 1 answers

0
saidtechnology On

That I know, It is possible to add a new conversion to an existing media collection in Laravel by using spalie MediaLibrary.

<?php
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class YourModel implements HasMedia
{
    use InteractsWithMedia;

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb')
             ->width(70)
             ->height(70);

        $this->addMediaConversion('block')
             ->width(100)
             ->height(100);

      
        $this->addMediaConversion('new_conversion')
             ->width(152)
             ->height(152);
    }
}
?>