Laravel-medialibrary: Single Collection bug with 5.7 ?

Created on 17 Oct 2018  路  6Comments  路  Source: spatie/laravel-medialibrary

Since I migrated to Laravel 5.7, all my single collection are not working anymore.

On upload, it seems that "clearMediaCollectionExcept" (called from FileAdder::processMediaItem) deletes the new uploaded file and not only the old one...

I did not identify the exact issue yet, I'll update if I find a fix.

bug

Most helpful comment

@ambengers, @anouarabdsslm I made the same error when trying to find the error(using the model_id instead of the media id in the path generator). Can it be you made this error too? I will close the issue for now.

All 6 comments

@Nuranto, @ambengers, @anouarabdsslm are you using an Custom Path generator(https://docs.spatie.be/laravel-medialibrary/v7/advanced-usage/using-a-custom-directory-structure) ?

Sorry I did not update...
Yes, I use a custom path, and that was the issue...
You must use media id as final folder....

It's actually specified in the doc :

There aren't any restrictions on how the directories can be named. When a Media-object gets deleted the package will delete its entire associated directory. To avoid tears or worse, make sure that every media gets stored its own unique directory.

@ambengers, @anouarabdsslm I made the same error when trying to find the error(using the model_id instead of the media id in the path generator). Can it be you made this error too? I will close the issue for now.

@rubenvanassche apparently I did (code below). So this means we cannot use model_id in the path generator at all? Or can we use model_id but have to be in conjunction with the media_id?

/**
     * Get the path for the given media, relative to the root storage path.
     *
     * @param  Spatie\MediaLibrary\Models\Media $media
     * @return string
     */
    public function getPath(Media $media): string
    {
        return $media->model_type . '/'
            . $media->model_id . '/'
            . $media->collection_name . '/';
    }

@ambengers that's right, you should not use the model_id.

@rubenvanassche thanks and noted!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronfullerton picture aaronfullerton  路  4Comments

denitsa-md picture denitsa-md  路  3Comments

amrnn90 picture amrnn90  路  3Comments

swash13 picture swash13  路  3Comments

jam1e picture jam1e  路  3Comments