images not showing using spatie media library in filamentphp
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Troubleshooting Images in FilamentPHP with Spatie Media Library
Dealing with file uploads, especially when integrating powerful packages like the Spatie Media Library with administrative interfaces like FilamentPHP, can sometimes lead to unexpected display issues. If your images are not showing up in the Filament admin panel despite correctly configuring the form and table columns, it usually points to a misalignment between how the file is stored, how Eloquent retrieves the path, and how Filament renders that path.
As a senior developer, I've seen this pattern repeatedly. The issue rarely lies within the Spatie package itself, but rather in the bridge connecting the storage layer (Spatie) to the presentation layer (Filament). Letâs dissect the common pitfalls and implement the robust solution.
## Understanding the Integration Point
The code snippets you provided demonstrate the correct intent: linking a file field via Spatie's file upload mechanism directly into a Filament Resource structure.
```php
// Form Schema Snippet
SpatieMediaLibraryFileUpload::make('thumbnail')->collection('posts')
// Table Column Snippet
SpatieMediaLibraryImageColumn::make('thumbnail')->collection('posts')
```
While these lines correctly tell Filament *what* field to expect, the failure usually occurs because the underlying Eloquent model or the relationship configuration isn't properly resolving the file URL. The image is stored on the disk (managed by Spatie), but the database column needs a specific format that Filament knows how to interpret as an image tag (`
`).
## The Root Cause: Resolving the File Path
The most frequent cause for this problem is that the data being pulled into the table or form is either storing the wrong identifier (e.g., just the filename instead of the full URL) or the relationship setup is incomplete.
When using Spatie Media Library, ensure that your Eloquent model correctly interacts with the media library setup. You need to ensure that when Filament requests the data for display, it receives a publicly accessible URL.
### Best Practice: Ensuring Public Access
If you are relying on the default behavior of `SpatieMediaLibraryFileUpload`, the paths stored in the database usually point to the file within your configured storage disk (e.g., `storage/app/public/...`). For Filament and web display, these paths must be accessible via a public URL.
Verify that your storage disk is correctly linked to the public web directory. This is a fundamental step when building applications on Laravel, as highlighted by best practices within the Laravel ecosystem itself. Make sure you are using the correct file handling methods provided by Laravel for this purpose.
## The Solution: Customizing the Column Display
Since you are using Spatie's specific column class (`SpatieMediaLibraryImageColumn`), the issue might be how it resolves the path. If the default resolution fails, we can manually force Filament to use the correct public URL stored by Spatie within your model relationship.
Instead of relying solely on the automatic mapping, you can override the column display method in your Filament Resource to explicitly pull the image URL from the related media item. This provides maximum control and resolves ambiguity.
Here is an example of how you might adjust your table definition within your `PostResource`:
```php
use Filament\Tables\Columns\ImageColumn;
use App\Models\Post; // Assuming this is your model
// Inside your form or table schema definition
ImageColumn::make('thumbnail')
->label('Post Thumbnail')
->getStateUsing(function (Post $record) {
// Assuming 'thumbnail' is a relationship to the media library items
$mediaItem = $record->thumbnail;
if ($mediaItem && $mediaItem->getFullUrl()) {
return $mediaItem->getFullUrl();
}
// Fallback if no image exists
return null;
})
```
By using `getStateUsing()`, you bypass any potential internal mapping conflicts and explicitly tell Filament to fetch the full, publicly accessible URL from the related media record. This approach ensures that whatever data Spatie stores is correctly rendered as an HTML `
` tag in your admin panel.
## Conclusion
Displaying files uploaded via external libraries within a framework like Filament requires careful orchestration between storage, Eloquent models, and presentation layers. The issue you are facing is a common integration hurdle, not a flaw in the Spatie package itself. By focusing on resolving the correct public URL within your model relationships and using methods like `getStateUsing()` in Filament, you gain complete control over how these assets are rendered. Remember, mastering the interplay between Laravel's core concepts and powerful packages is key to building robust applications, just as emphasized by the principles of modern application development on platforms like [laravelcompany.com](https://laravelcompany.com).