MediaLibrary Integration
The package ships an opt-in integration with spatie/laravel-medialibrary. When enabled, the featured-image upload uses SpatieMediaLibraryFileUpload instead of the default FileUpload.
FileUpload — no crash. Flipping features.media_library without installing MediaLibrary is a no-op.Enable
- Install the package:Terminal
composer require spatie/laravel-medialibrary php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations" php artisan migrate - Flip the flag:config/filament-blog.php
'features' => [ 'media_library' => true, ], - Use the form as usual — the featured-image field now writes to the MediaLibrary
mediatable on afeatured_imagecollection.
Form-side only (for now)
This integration covers the admin form-component swap only. The model-side integration (implementing HasMedia, registering collections via registerMediaCollections(), migrating existing featured_image string column data) is intentionally deferred — that requires careful schema-migration design that doesn't fit a feature-flag layer.
If you want the full integration today, override the Post model in your app:
namespace App\Models;
use ManukMinasyan\FilamentBlog\Models\Post as BasePost;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection;
class BlogPost extends BasePost implements HasMedia
{
use InteractsWithMedia;
public function registerMediaCollections(): void
{
$this->addMediaCollection('featured_image')->singleFile();
}
}
Then point the package at your model:
// (post_model is not currently a config key — track this in
// Phase 3 follow-up; for now the package always uses its own Post)
v1.5.Migrating existing featured_image data
When Phase 3 lands, existing posts with a featured_image string path will be migrated to MediaLibrary entries via a console command. Until then, two options:
- Stay on
FileUpload— leave the flag off. No migration required. - Manual migration — write your own script to copy
featured_imagefiles into MediaLibrary on afeatured_imagecollection.
Both Tapix and FilaForms blogs (which this package replaces) use the same string-column approach, so flipping the flag without migration leaves you in a usable state — new posts go to MediaLibrary, old posts keep using the string path. The shipped views render whichever exists.