sarmadict / filament-media
A reusable Filament 5 media library, filesystem browser, and media picker for Laravel applications.
Requires
- php: ^8.3
- filament/filament: ^5.0
- illuminate/auth: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/filesystem: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/pagination: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- livewire/livewire: ^4.0
Requires (Dev)
- laravel/pint: ^1.27
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A reusable media library for Laravel and Filament 5. It provides:
- a filesystem-aware Filament media browser;
- a reusable
MediaPickerform field; - uploads registered in a
media_filestable; - polymorphic
media_attachments; - public / temporary preview URL resolution;
- safe file deletion with configurable usage checks;
- directory browsing, creation, rename, deletion, and registration;
- configurable disks and authorization;
- time-ordered UUIDs with date, UUID-prefix, or custom upload directories;
- UUID or hash filenames, configurable globally and per field;
- picker results stored as media IDs, UUIDs, filenames, or complete paths.
Install
composer require sarmadict/filament-media php artisan vendor:publish --tag=filament-media-config php artisan migrate
Register the panel plugin:
use Sarmadict\FilamentMedia\FilamentMediaPlugin; public function panel(Panel $panel): Panel { return $panel // ... ->plugin(FilamentMediaPlugin::make()); }
Use the picker:
use Sarmadict\FilamentMedia\Filament\Forms\Components\MediaPicker; MediaPicker::make('cover_media_id')->images();
Set picker.modal_width in the config or override it per field with Filament's Width enum:
use Filament\Support\Enums\Width; MediaPicker::make('cover_media_id')->images()->modalWidth(Width::Screen);
The default normal preserves the current size. screen fills the viewport with a small margin; standard widths such as 5xl / Width::FiveExtraLarge are also supported.
Store the disk-relative file path instead of the media ID when needed:
MediaPicker::make('cover_path') ->images() ->resultType(MediaPicker::RESULT_PATH) ->disk('public');
Configure a field independently of application defaults:
MediaPicker::make('cover_uuid') ->images() ->resultType(MediaPicker::RESULT_UUID) ->uploadPath('posts/covers') ->uploadPathType('uuid_prefix') ->uploadFilenameType('uuid');
The default upload path is uploads/{Y}/{m}/{d}/{uuid}.{extension}. Set FILAMENT_MEDIA_UPLOAD_PATH_TYPE=uuid_prefix for uploads/{uuid first 2 characters}/{filename}, or flat for an exact base directory. FILAMENT_MEDIA_FILENAME_TYPE chooses uuid (default) or hash. Set FILAMENT_MEDIA_UPLOAD_PATH= for an empty base directory.
Run php artisan migrate after upgrading to add UUIDs to existing media rows. Existing files retain their locations and filenames.
See docs/index.md for the complete documentation.