Filament Attachment Library is a Laravel package that enables a polymorphic morphMany relationship to handle file attachments across multiple Eloquent models. Seamlessly integrated with Filament, it offers a clean, reusable, and consistent approach to managing file uploads through Filament resource forms and tables—making attachment handling simple and scalable across your application.
Install the package via Composer:
composer require victorscatolon/filament-attachment-library
Then publish the package's migration files:
php artisan vendor:publish --tag="filament-attachment-library-migrations"
php artisan make:model MyModel
InteractsWithAttachments
trait to your model to define the polymorphic relationship:use VictorScatolon\FilamentAttachmentLibrary\Core\InteractsWithAttachments; class MyModel extends Model{ use InteractsWithAttachments;}
form
method, include the AttachmentLibraryFileUpload
component to allow users to upload files:use VictorScatolon\FilamentAttachmentLibrary\Forms\Components\AttachmentLibraryFileUpload; public static function form(Form $form): Form{ return $form ->schema([ AttachmentLibraryFileUpload::make(), ]);}
HandleAttachments
trait in your CreateRecord
class:CreateRecord component
use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments; class CreateMyModel extends CreateRecord{ use HandleAttachments;}
EditRecord component
use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments; class EditMyModel extends EditRecord{ use HandleAttachments;}
To use the Attachment Library within a Relation Manager form, follow these steps:
HandleAttachments
trait to your RelationManager
class:use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments; class MyRelationManager extends RelationManager{ use HandleAttachments;}
dehydrated(true)
on the file upload field
Make sure the attachment field is dehydrated so that the file data is available during form processing:public function form(Form $form): Form{ return $form ->schema([ AttachmentFileUpload::make()->dehydrated(true), ]);}
CreateAction
with an after()
callback to manually handle the attachments after the record is created:public function table(Table $table): Table{ return $table->headerActions([ Tables\Actions\CreateAction::make() ->after(function ($record, $data) { $attachments = $data['attachments']; $this->handleAttachments($record, $attachments); }), ]);}
✅ Note: Make sure the field name in the $data array matches the field key used in the AttachmentLibraryFileUpload::make() definition.
For a detailed list of recent changes, updates, and improvements, please refer to the Changelog.
Contributions are welcome! To get started, please read the Contribution Guide.
Developed and maintained by @victorscatolon.
Thanks to all the amazing contributors who help improve this package.
This project is open-source software licensed under the MIT License.
Senior Full Stack Developer with solid experience in Laravel and Node.js for backend development, and expertise in Vue.js and React for frontend development. Focused on continuous growth in the backend field, I aim to enhance my skills in software architecture, as well as the creation of scalable and high-performance APIs.