finller/filament-media-plugin
最新稳定版本:v5.1.0
Composer 安装命令:
composer require finller/filament-media-plugin
包简介
Filament support for `elegantly/laravel-media`.
README 文档
README
Installation
Install the plugin with Composer:
composer require elegantly/filament-media-plugin:"^4.0" -W
If you haven't already done so, you need to publish the migration to create the media table:
php artisan vendor:publish --tag="media-migrations"
Run the migrations:
php artisan migrate
You must also prepare your Eloquent model for attaching media.
For more information, check out the documentation.
Form component
You may use the field in the same way as the original file upload field:
use Filament\Forms\Components\ElegantlyMediaFileUpload; ElegantlyMediaFileUpload::make('avatar')
The media file upload supports all the customization options of the original file upload component.
Passing a collection
Optionally, you may pass a collectionName() allows you to group files into categories:
use Filament\Forms\Components\ElegantlyMediaFileUpload; ElegantlyMediaFileUpload::make('avatar') ->collectionName('avatars')
Configuring the storage disk and directory
By default, files will be uploaded publicly to your storage disk defined in the collection.
Alternatively, you can manually set the disk with the disk() method:
use Filament\Forms\Components\ElegantlyMediaFileUpload; ElegantlyMediaFileUpload::make('attachment') ->disk('s3')
Reordering files
In addition to the behavior of the normal file upload, Elegantly's Media also allows users to reorder files.
To enable this behavior, use the reorderable() method:
use Filament\Forms\Components\ElegantlyMediaFileUpload; ElegantlyMediaFileUpload::make('attachments') ->multiple() ->reorderable()
You may now drag and drop files into order.
Adding metadata
You may pass in [metadata] when uploading files using the metadata() method:
use Filament\Forms\Components\ElegantlyMediaFileUpload; ElegantlyMediaFileUpload::make('attachments') ->multiple() ->metadata(['zip_filename_prefix' => 'folder/subfolder/'])
Using conversions
You may also specify a conversionName() to load the file from showing it in the form, if present:
use Filament\Forms\Components\ElegantlyMediaFileUpload; ElegantlyMediaFileUpload::make('attachments') ->conversionName('thumb')
Filtering media
It's possible to target a file upload component to only handle a certain subset of media in a collection. To do that, you can filter the media collection using the filterMediaUsing() method. This method accepts a function that receives the $media collection and manipulates it. You can use any collection method to filter it.
For example, you could scope the field to only handle media that has certain custom properties:
use Filament\Schemas\Components\Utilities\Get; use Filament\Forms\Components\ElegantlyMediaFileUpload; use Illuminate\Support\Collection; ElegantlyMediaFileUpload::make('images') ->metadata(fn (Get $get): array => [ 'gallery_id' => $get('gallery_id'), ]) ->filterMediaUsing( fn (Collection $media, Get $get): Collection => $media->where( 'metadata.gallery_id', $get('gallery_id') ), )
Using media for rich editor file attachments
You can use media to store file attachments in the rich editor. To do this, you must register a rich content attribute on your model, similar to how a media library collection is registered. You should call fileAttachmentProvider() on the attribute registration, passing in a ElegantlyMediaFileAttachmentProvider::make() object:
use Filament\Forms\Components\RichEditor\FileAttachmentProviders\ElegantlyMediaFileAttachmentProvider; use Filament\Forms\Components\RichEditor\Models\Concerns\InteractsWithRichContent; use Filament\Forms\Components\RichEditor\Models\Contracts\HasRichContent; use Illuminate\Database\Eloquent\Model; class Post extends Model implements HasRichContent { use InteractsWithRichContent; public function setUpRichContent(): void { $this->registerRichContent('content') ->fileAttachmentsProvider(ElegantlyMediaFileAttachmentProvider::make()); } }
A media collection with the same name as the attribute (content in this example) will be used for the file attachments. The collection must not contain any other media apart from file attachments for that attribute, since Filament will clear any unused media from the collection when the model is saved. To customize the name of the collection, you can pass it to the collectionName() method of the provider:
use Filament\Forms\Components\RichEditor\FileAttachmentProviders\ElegantlyMediaFileAttachmentProvider; use Filament\Forms\Components\RichEditor\Models\Concerns\InteractsWithRichContent; use Filament\Forms\Components\RichEditor\Models\Contracts\HasRichContent; use Illuminate\Database\Eloquent\Model; class Post extends Model implements HasRichContent { use InteractsWithRichContent; public function setUpRichContent(): void { $this->registerRichContent('content') ->fileAttachmentsProvider( ElegantlyMediaFileAttachmentProvider::make() ->collectionName('content-file-attachments'), ); } }
Table column
To use the media library image column:
use Filament\Tables\Columns\ElegantlyMediaImageColumn; ElegantlyMediaImageColumn::make('avatar')
The media library image column supports all the customization options of the original image column.
Passing a collection
Optionally, you may pass a collectionName():
use Filament\Tables\Columns\ElegantlyMediaImageColumn; ElegantlyMediaImageColumn::make('avatar') ->collectionName('avatars')
By default, only media without a collection (using the default collection) will be shown. If you want to show media from all collections, you can use the allCollections() method:
use Filament\Tables\Columns\ElegantlyMediaImageColumn; ElegantlyMediaImageColumn::make('avatar') ->allCollections()
Using conversions
You may also specify a conversionName() to load the file from showing it in the table, if present:
use Filament\Tables\Columns\ElegantlyMediaImageColumn; ElegantlyMediaImageColumn::make('avatar') ->conversionName('thumb')
Filtering media
It's possible to target the column to only display a subset of media in a collection. To do that, you can filter the media collection using the filterMediaUsing() method. This method accepts a function that receives the $media collection and manipulates it. You can use any collection method to filter it.
For example, you could scope the column to only display media that has certain custom properties:
use Filament\Tables\Columns\ElegantlyMediaImageColumn; use Illuminate\Support\Collection; ElegantlyMediaImageColumn::make('images') ->filterMediaUsing( fn (Collection $media): Collection => $media->where( 'metadata.gallery_id', 12345, ), )
Infolist entry
To use the media library image entry:
use Filament\Infolists\Components\ElegantlyMediaImageEntry; ElegantlyMediaImageEntry::make('avatar')
The media library image entry supports all the customization options of the original image entry.
Passing a collection
Optionally, you may pass a collectionName():
use Filament\Infolists\Components\ElegantlyMediaImageEntry; ElegantlyMediaImageEntry::make('avatar') ->collectionName('avatars')
By default, only media without a collection (using the default collection) will be shown. If you want to show media from all collections, you can use the allCollections() method:
use Filament\Infolists\Components\ElegantlyMediaImageEntry; ElegantlyMediaImageEntry::make('avatar') ->allCollections()
Using conversions
You may also specify a conversionName() to load the file from showing it in the infolist, if present:
use Filament\Infolists\Components\ElegantlyMediaImageEntry; ElegantlyMediaImageEntry::make('avatar') ->conversionName('thumb')
Filtering media
It's possible to target the entry to only display a subset of media in a collection. To do that, you can filter the media collection using the filterMediaUsing() method. This method accepts a function that receives the $media collection and manipulates it. You can use any collection method to filter it.
For example, you could scope the entry to only display media that has certain custom properties:
use Filament\Tables\Columns\ElegantlyMediaImageEntry; use Illuminate\Support\Collection; ElegantlyMediaImageEntry::make('images') ->filterMediaUsing( fn (Collection $media): Collection => $media->where( 'metadata.gallery_id', 12345, ), )
finller/filament-media-plugin 适用场景与选型建议
finller/filament-media-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.01k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 finller/filament-media-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 finller/filament-media-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-09