mardi 7 août 2018

Laravel media library error: Call to a member function first() on null

I am new in using the Laravel Media Library v6. I want to get the Url of the uploaded file. but it returns an error:

Internal Server Error(500): Call to a member function getUrl() on null

here is my code where $material is the Material model which is connected to a table called Media, where the collection_name column is located.

            $material_media   = $material->getMedia();

        $material->file_path    = $material_media->first(function ($value) {
            return $value->collection_name === 'materials/files';
        })->getUrl();

getMedia() does its job but getUrl() does not. Am I missing something or forgot to add?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire