承接 waad/filament-media 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

waad/filament-media

Composer 安装命令:

composer require waad/filament-media

包简介

Filament integration for waad/media package for Media Upload Locally Or Cloud S3

README 文档

README

Logo

Filament Media

This package integrates Filament v3/v4/v5 with the waad/media manager. It is an alternative to spatie/laravel-medialibrary for projects on waad/media. The MediaUpload form component aligns with your Eloquent model’s registerCollections() (single vs multiple, disks, labels).

Requirements

  • PHP: ^8.1
  • Filament: ^3.0|^4.0|^5.0
  • Livewire: ^3.5|^4.0
  • waad/media: ^4.1

Installation

You can install the package via composer:

composer require waad/filament-media

Setup & Usage

Since this package works in tandem with waad/media, your Eloquent Models should use the HasMedia trait and implement registerCollections: waad/media Package.

php artisan vendor:publish --provider="Waad\Media\MediaServiceProvider"
use Illuminate\Database\Eloquent\Model;
use Waad\Media\HasMedia;

class Post extends Model
{
    use HasMedia;

    public function registerCollections(array $attributes = []): array
    {
        return [
            'avatar' => [
                'disk' => 's3',
                'bucket' => 'avatars',
                'label' => 'User Avatar',
                'single' => true, // Only keeps one file
            ],
            'gallery' => [
                'disk' => 'public',
                'bucket' => 'photos',
                'label' => 'Photo Gallery',
                'single' => false, // Allows multiple files
            ],
        ];
    }
}

MediaUpload::make('name') uses the field name as the waad/media collection by default. Call ->collection(...) only when the Filament field name should differ from the collection key (string), or when the collection must be resolved at runtime (Closure); pass null to rely on evaluation falling back to the field name.

Now, in your Filament resource or form:

use Waad\FilamentMedia\Forms\Components\MediaUpload;

public static function form(Form $form): Form
{
    return $form
        ->schema([
            // Single file when registerCollections has 'single' => true for this key
            MediaUpload::make('avatar'),

            // Multiple files when 'single' => false; reorderable uses waad/media `index`
            MediaUpload::make('gallery')
                ->reorderable()
                ->image()
                ->maxSize(2048),

            // Single vs multiple follows `registerCollections`; other FileUpload APIs apply as usual
        ]);
}

The component loads existing media IDs for previews, syncs new uploads via syncMedia, removes files with deleteMedia, and persists reorder when only existing items change.

Reordering multiple files (index)

For collections with 'single' => false, you can enable drag-and-drop reordering with Filament’s reorderable() (same as FileUpload). Order is stored in waad/media’s index column on the media table.

  • Loading the form: existing files are listed sorted by index, then by id, so the UI matches the saved order.
  • Saving the form: when only existing media are present (no new uploads in that save), the component writes the current list order back to the database as index values (1, 2, 3, …) for that collection.
MediaUpload::make('gallery')
    ->reorderable()
    ->image(),

Use this together with a multi-file collection in registerCollections(). Single-file collections ignore ordering.

Preview images in tables

In list/table views, use Filament’s ImageColumn and resolve URLs from your model with waad/media’s getCollectionUrls() (provided by HasMedia). Pass the same collection name you use in registerCollections() and in MediaUpload::make(...).

ImageColumn

use Filament\Tables\Columns\ImageColumn;

ImageColumn::make('banner')
    ->getStateUsing(fn ($record) => $record->getCollectionUrls('banner')),
ImageColumn::make('gallery')
    ->getStateUsing(fn ($record) => $record->getCollectionUrls('gallery')),
  • For a single-file collection ('single' => true), getCollectionUrls typically returns one URL string (or an empty value when there is no file).
  • For a multi-file collection, it returns an array of URLs; ImageColumn can show them as a stacked preview when the state is an array.

Adjust the column name (banner here) to match your collection key.

Pruning old media

waad/media registers the media:prune Artisan command. It removes media files and database rows according to the retention setting prune_media_after_day in your published config/media.php (see the waad/media docs for details).

Run it manually or on a schedule (for example Laravel’s scheduler in routes/console.php):

php artisan media:prune

Testing

This package uses Pest for testing. To run tests:

composer test

License

This package is open-sourced software licensed under the MIT license.

waad/filament-media 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-02