F
Filament5mo ago
Luiz

Spatie Media Library records media but does not display it.

I am using the Spatie Media Library package (https://filamentphp.com/plugins/filament-spatie-media-library). In the form I created the upload:
Forms\Components\SpatieMediaLibraryFileUpload::make('media')
->label('')
->multiple()
->image()
->imageEditor()
->reorderable()
->appendFiles()
Forms\Components\SpatieMediaLibraryFileUpload::make('media')
->label('')
->multiple()
->image()
->imageEditor()
->reorderable()
->appendFiles()
After saving the form, the media record is created in the Media table correctly, but the media disappears from my form as if it were empty. I also have the media column in my table (which I previously used with common upload), but nothing is saved in it. I believe it is not necessary. However, on my blade page I am trying to display the image but the return is empty:
$record->getFirstMediaUrl()
$record->getFirstMediaUrl()
What am I doing wrong?
17 Replies
developer
developer5mo ago
what's your storage driver (local, S3, etc)? if local maybe you forgot to run php artisan storage:link
Luiz
LuizOP5mo ago
local and the link already exists. everything works fine with the regular upload form and the image is displayed correctly. However, with Spatie Media Library it simply doesn't work.
toeknee
toeknee5mo ago
Whats the browser console say?
Luiz
LuizOP5mo ago
Nothing, it's empty. I tried in 3 different browsers and the console doesn't have any errors I also tried another storage driver and the image is saved on the server and the record created in the database. However, it is not displayed in the form after saving nor when I need to display it.
toeknee
toeknee5mo ago
Is this a custom livewire component?
Luiz
LuizOP5mo ago
no. Edit Resource Page
toeknee
toeknee5mo ago
Hm........ Not making much sense .. Please ensure you are updated using the latest version, with filament upgrade run and with npm run dev.
Luiz
LuizOP5mo ago
filament/filament 3.2.58 filament/spatie-laravel-media-library-plugin 3.2
toeknee
toeknee5mo ago
So upgrade filament.... you are 40 versions behind media library plugin might be out of date too.
Luiz
LuizOP5mo ago
I'll check. thanks I updated all the packages and I'm still having the same problem. I even removed the vendor and node_modules folder and reinstalled everything, cleared cache, etc.
toeknee
toeknee5mo ago
Ok… can you create a reproduction repository? So we can review?
Luiz
LuizOP5mo ago
I created a new laravel installation and tested it and everything worked fine. Thank you for your help.
developer
developer5mo ago
have you checked the .env APP_URL ? make sure you don't have a slash at the end - the correct format is APP_URL=myproject.localhost
toeknee
toeknee5mo ago
check the asset url too
Luiz
LuizOP5mo ago
I tried with http://localhost and http://localhost:8000 and in the published project I tried using the site's https url and the problem is the same. Where can I find the asset url? The interesting thing is that if I start a new project and install only filament and spatie-laravel-media-library-plugin everything works fine. But then I finished installing the packages I need and created the resources I need and then it stopped working again. It seems to be incompatibility with some package or something.
toeknee
toeknee5mo ago
ASSET_URL= in the .env So it sounds like you are fighting with a URL issue, Have you set the APP_URL is set correctly in the? Maybe also try using Herd for your Stack
developer
developer5mo ago
how you serve your app in your local environment? i recommend using laravel herd remember to remove the slash at the end of the url
good: http://mylaravelapp.localhost
bad: http://mylaravelapp.localhost/
good: http://mylaravelapp.localhost
bad: http://mylaravelapp.localhost/
Want results from more Discord servers?
Add your server