van-ons/filament-attachment-library
Composer 安装命令:
composer require van-ons/filament-attachment-library
包简介
A Filament library for attaching files to Eloquent models.
README 文档
README
Filament Attachment Library
Filament package for easy attachment uploading and browsing.
Quick start
For Filament version compatibility, see Compatibility.
Installation
The Filament Attachment Library can be installed using Composer by running the following command:
composer require van-ons/filament-attachment-library:^2.0
An installation command is available that ensures that the migrations and assets are installed:
php artisan filament-attachment-library:install
The templates in this package use TailwindCSS. To ensure the styling is rendered correctly, a custom Filament
theme must be set up, and the tailwind.config.js file should be extended.
Create the custom Filament theme and follow the instructions in the terminal to set it up:
php artisan make:filament-theme [PANEL_NAME]
Add the following to the generated theme.css file:
// resources/css/filament/[PANEL_NAME]/theme.css @source '../../../../vendor/van-ons/filament-attachment-library/resources/**/*.blade.php'
Note
Make sure to follow the instructions in the terminal to register your custom Filament theme in the admin panel.
If your project is using Vite, you may have to register the custom theme as follows:
->viteTheme('resources/css/filament/[PANEL_NAME]/theme.css', 'build')
By default, this package uses the public disk defined in filesystems.php. This can be overridden by adding the following
to the project's .env file:
ATTACHMENTS_DISK=disk_name_here
Note
It is advised to use a disk without any other files. This prevents file conflicts.
The glide.php and attachment-library.php files contain more configuration options.
Prepare model
Register the plugin in the desired Filament panel:
namespace App\Providers\Filament; use VanOns\FilamentAttachmentLibrary\FilamentAttachmentLibrary; class ExamplePanelProvider extends PanelProvider { public function panel(Panel $panel): Panel { return $panel ->plugin( FilamentAttachmentLibrary::make()->navigationGroup('Files') ); } }
Usage
The attachment field can be used in two ways: either to store the attachments in a specific column of your model,
or to store the attachments in the attachments relationship by using the HasAttachments trait and the relationship() method.
(Optional) Add the HasAttachments trait to your desired model:
namespace App\Models; use Illuminate\Database\Eloquent\Model; use VanOns\LaravelAttachmentLibrary\Concerns\HasAttachments; class ModelName extends Model { use HasAttachments; // ... }
This will add the attachments() relationship which links one or more
attachments to your model.
Then, in your form schema, add the AttachmentField:
namespace App\Filament\Resources; use Filament\Forms; use Filament\Forms\Form; use VanOns\FilamentAttachmentLibrary\Forms\Components\AttachmentField; public static function form(Form $form): Form { return $form ->schema([ // ... // If you want to store the attachments in a column AttachmentField::make('featured_image'), // Or if you want to store attachments in the attachments relationship with a specific collection name AttachmentField::make('gallery')->relationship(), // Or if you want the collection name to be different from the field name AttachmentField::make('gallery')->relationship()->collection('product_gallery'), ]); }
(Optional) When using the relationship() method, you can filter the attachments by collection name. To make this easier you can add a separate relationship method to your model:
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphToMany; use VanOns\LaravelAttachmentLibrary\Concerns\HasAttachments; class ModelName extends Model { use HasAttachments; public function gallery(): MorphToMany { return $this->attachmentCollection('gallery'); } }
Finally, at the front end, the laravel-attachment-library-image Blade component can be used to display attachments as image.
Glide is used to scale the image up or down. The src argument may be an Attachment instance, or the id as string/integer.
<x-laravel-attachment-library-image :src="$image" />
For more information refer to the Laravel Attachment Library documentation.
Documentation
Please see the documentation for detailed information about installation and usage.
Contributing
Please see Contributing for more information about how you can contribute.
JavaScript assets
The package's Alpine components live in resources/js/plugin.js and are bundled into the committed
resources/dist/filament-attachment-library.js artifact. After changing any JS, rebuild and commit the artifact:
npm install npm run build
Consuming applications republish the bundle automatically on composer updates through Filament's standard
filament:upgrade composer hook; apps without that hook must run php artisan filament:assets manually.
Changelog
Please see Changelog for more information about what has changed recently.
Upgrading
Please see Upgrading for more information about how to upgrade.
Security
Please see Security for more information about how we deal with security.
Credits
We would like to thank the following contributors for their contributions to this project:
License
The scripts and documentation in this project are released under the MIT License.
van-ons/filament-attachment-library 适用场景与选型建议
van-ons/filament-attachment-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.1k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2025 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「models」 「eloquent」 「attachments」 「filament」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 van-ons/filament-attachment-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 van-ons/filament-attachment-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 van-ons/filament-attachment-library 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Wordpress Query Builder class library for custom models and data querying.
A Laravel Eloquent model trait for translatable resource
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Help to manage meta data on Laravel Eloquent model
A package to cast json fields, each sub-keys is castable
A Laravel package for managing model drafts.
统计信息
- 总下载量: 5.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-22
