定制 victorscatolon/filament-attachment-library 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

victorscatolon/filament-attachment-library

Composer 安装命令:

composer require victorscatolon/filament-attachment-library

包简介

Easily manage file attachments across multiple models using a clean, polymorphic approach in your Filament app.

README 文档

README

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.

🚀 Installation

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"

⚙️ Configuration

  1. Create your model If you haven’t already, create a new Eloquent model:
php artisan make:model MyModel
  1. Enable attachments on your model Add the InteractsWithAttachments trait to your model to define the polymorphic relationship:
use VictorScatolon\FilamentAttachmentLibrary\Core\InteractsWithAttachments;

class MyModel extends Model
{
    use InteractsWithAttachments;
}
  1. Add the file upload field to your Filament form In your Filament resource's 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(),
        ]);
}
  1. Enable attachment handling in the CreateRecord component To ensure attachments are saved properly when creating a new model, use the HandleAttachments trait in your CreateRecord class:

CreateRecord component

use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments;

class CreateMyModel extends CreateRecord
{
    use HandleAttachments;
}
  1. Enable attachment handling in the EditRecord component Likewise, use the HandleAttachments trait in your EditRecord class to manage attachments during updates:

EditRecord component

use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments;

class EditMyModel extends EditRecord
{
    use HandleAttachments;
}

🗂️ Relation Managers

To use the Attachment Library within a Relation Manager form, follow these steps:

  1. Use the HandleAttachments trait Add the HandleAttachments trait to your RelationManager class:
use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments;

class MyRelationManager extends RelationManager
{
    use HandleAttachments;
}
  1. Set 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),
        ]);
}
  1. Add a custom create action to the table You’ll need to define a custom 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.

📦 Changelog

For a detailed list of recent changes, updates, and improvements, please refer to the Changelog.

🤝 Contributing

Contributions are welcome! To get started, please read the Contribution Guide.

👨‍💻 Credits

Developed and maintained by @victorscatolon.
Thanks to all the amazing contributors who help improve this package.

📄 License

This project is open-source software licensed under the MIT License.

victorscatolon/filament-attachment-library 适用场景与选型建议

victorscatolon/filament-attachment-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 110 次下载、GitHub Stars 达 7, 最近一次更新时间为 2025 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「media」 「library」 「laravel」 「attachment」 「file upload」 「polymorphic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 victorscatolon/filament-attachment-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 victorscatolon/filament-attachment-library 我们能提供哪些服务?
定制开发 / 二次开发

基于 victorscatolon/filament-attachment-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 110
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-11