I am using FilamentPHP and Spatie media library. Additionally, I am using the Spatie media library FilamentPHP plugin in order to show and upload the images in my admin panel.
However, the images are not being uploaded and stored at all!
This is my model:
use IlluminateDatabaseEloquentModel;
use SpatieMediaLibraryHasMedia;
use SpatieMediaLibraryInteractsWithMedia;
class OrderItem extends Model implements HasMedia
{
use InteractsWithMedia;
public function registerMediaCollections(): void
{
$this->addMediaCollection('designs')
->useDisk('designFiles');
}
}
My filesystem.php:
'designFiles' => [
'driver' => 'local',
'root' => storage_path('app/public/designs'),
'url' => env('APP_URL') . '/storage/designs',
'visibility' => 'public',
],
My filament resource:
SpatieMediaLibraryFileUpload::make('design')
->collection('designs')
->downloadable()
->multiple(),
The image I upload on my filament resource are being stored temporarily at storage/app/livewire-tmp
. However, there is no entry in my spatie media library media
table and the image is also not being saved to the desired disk (designFiles).
I have already tried to debug this problem but there is no error event being logged at all. I am using Laravel Valet and I have also added the port to my APP_URL variable with my .env
file as suggested here but it did not help me.
I have also run php artisan storage:link
but because I did run this command before already, it did not change anything. The image is still not being saved.
Those are the versions I use:
"php": "^8.2",
"filament/filament": "^3.2",
"filament/spatie-laravel-media-library-plugin": "^3.2",
"laravel/framework": "^11.9",
"spatie/laravel-medialibrary": "^11.8"
Anybody has an idea how to fix this problem?
Kind regards
2
Answers
1. In your controller or a tinker session, try something like this:
2.Also check the configuration
3.Try to check storage permissions
In this you can create debug log as well to check and verify that Filament resource saves the data.
Please let me know if this could help you.
This is not exactly a solution as I do not have a clear picture of your precise setup, but it may help you track down the problem.
I applied the parameters that you specified and my media files were successfully saved to the correct location (
app/public/designs
). I however used"spatie/laravel-medialibrary": "^11.9"
Add the following code to have a finer-grained view of what is going on when you save an
OrderItem
:app/Providers/AppServiceProvider.php
This should log any queries that insert to
order_items
or amedia
. I’ve assumed these are the names you have for the matching tables in your database. If the names you are using are different, then update the code accordingly.The logged transactions can be viewed in
storage/logs/laravel.log
. Newer log entries are at the very end of the file.In the case of a successful creation of an
OrderItem
, the log file should contain lines beginning with:[TIME_STAMP] local.INFO: insert into 'order_items'...
[TIME_STAMP] local.INFO: insert into 'media'...
The media file gets copied to
app/public/designs
afterinsert into 'media'...
has succeeded. Lastly, the uploaded temporary file is deleted fromstorage/app/livewire-tmp
.With these insights, you can figure out at what point the problem is occurring. If
order_items
has a new entry, but there isn’t a matching one inmedia
, then the process failed before handling the media.My best guess is that you have a file permissions problem that prevents the copying of
storage/app/livewire-tmp/image.png
toapp/public/designs/image.png
. And just to be sure, you can try to save anOrderItem
that does not have any media fields so as to establish there isn’t any other non-media related issue.