A media picker/manager plugin for Filament Admin.
Warning This package does not work with Spatie Media Library.
You can install the package via composer then run the installation command:
composer require awcodes/filament-curator
php artisan curator:install
If you are using the stand-alone forms package then you will need to include the Curator modal in your layout file, typically you would place this, before the closing body
tag.
<x-curator::modals.modal />
In an effort to align with Filament's theming methodology you will need to use a custom theme to use this plugin.
Note If you have not set up a custom theme and are using a Panel follow the instructions in the Filament Docs first. The following applies to both the Panels Package and the standalone Forms package.
You will also need to add cropper.js.
npm install -D cropperjs
@import '<path-to-node-modules>/cropperjs/dist/cropper.css';@import '<path-to-vendor>/awcodes/filament-curator/resources/css/plugin.css';
tailwind.config.js
file.content: [ './vendor/awcodes/filament-curator/resources/**/*.blade.php',]
If you are upgrading from 2.x to 3.x you will also need to run:
php artisan curator:upgrade
This will update Curator's database schema and create a backup of your media table that can be deleted after upgrade should you choose to do so.
CurationPreset
will need to be updated to the new format.GliderFallback
will need to be updated to the new format.Global settings can be managed through the plugin's config file. You can publish the config file using the following:
php artisan vendor:publish --tag="curator-config"
If you are using Filament Panels you will need to add the Plugin to your Panel's configuration. This will register the plugin's resources with the Panel. All methods are optional, and will be read from the config file if not provided.
public function panel(Panel $panel): Panel{ return $panel ->plugins([ \Awcodes\Curator\CuratorPlugin::make() ->label('Media') ->pluralLabel('Media') ->navigationIcon('heroicon-o-photo') ->navigationGroup('Content') ->navigationSort(3) ->navigationCountBadge() ->registerNavigation(false) ->defaultListView('grid' || 'list') ->resource(\App\Filament\Resources\CustomMediaResource::class) ]);}
Include the CuratorPicker field in your forms to trigger the modal and either
select an existing image or upload a new one. Some common methods
from Filament's FileUpload
component can be used to help with sizing,
validation, etc. for specific instances of each CuratorPicker.
use Awcodes\Curator\Components\Forms\CuratorPicker;Â CuratorPicker::make(string $fieldName) ->label(string $customLabel) ->buttonLabel(string | Htmlable | Closure $buttonLabel) ->color('primary|secondary|success|danger') // defaults to primary ->outlined(true|false) // defaults to true ->size('sm|md|lg') // defaults to md ->constrained(true|false) // defaults to false (forces image to fit inside the preview area) ->pathGenerator(DatePathGenerator::class|UserPathGenerator::class) // see path generators below ->lazyLoad(bool | Closure $condition) // defaults to true ->listDisplay(bool | Closure $condition) // defaults to true ->tenantAware(bool | Closure $condition) // defaults to true ->defaultPanelSort(string | Closure $direction) // defaults to 'desc' // see https://filamentphp.com/docs/2.x/forms/fields#file-upload for more information about the following methods ->preserveFilenames() ->maxWidth() ->minSize() ->maxSize() ->rules() ->acceptedFileTypes() ->disk() ->visibility() ->directory() ->imageCropAspectRatio() ->imageResizeTargetWidth() ->imageResizeTargetHeight() ->multiple() // required if using a relationship with multiple media ->relationship(string $relationshipName, string 'titleColumnName') ->orderColumn('order') // only necessary to rename the order column if using a relationship with multiple media
Form component
CuratorPicker::make('featured_image_id') ->relationship('featured_image', 'id'),
Model
use Awcodes\Curator\Models\Media;Â public function featuredImage(): BelongsTo{ return $this->belongsTo(Media::class, 'featured_image_id', 'id');}
Form component
CuratorPicker::make('product_picture_ids') ->multiple() ->relationship('product_pictures', 'id') ->orderColumn('order'), // only necessary if you need to rename the order column
Model
use Awcodes\Curator\Models\Media;Â public function productPictures(): BelongsToMany{ return $this ->belongsToMany(Media::class, 'media_post', 'post_id', 'media_id') ->withPivot('order') ->orderBy('order');}
Note: The current implementation supports morphable relationships in forms, but it is not yet functional in table columns. Further adjustments are required for full compatibility.
Example Migration
Schema::create('media_items', function (Blueprint $table) { $table->id(); $table->morphs('mediable'); $table->foreignId('media_id')->constrained()->onDelete('cascade'); $table->integer('order'); $table->string('type'); $table->timestamps();});
Model
public function media(): MorphMany{ return $this->morphMany(MediaItem::class, 'mediable')->orderBy('order');}
Form component
CuratorPicker::make('document_ids') ->multiple() ->relationship('media', 'id') ->orderColumn('order') // Optional: Rename the order column if needed ->typeColumn('type') // Optional: Rename the type column if needed ->typeValue('document'); // Optional: Specify the type value if using types
By default, Curator will use the directory and disk set in the config to
store your media. If you'd like to store the media in a different way
Curator comes with Path Generators that can be used to modify the behavior.
Just set the one you want to use globally in the config or per instance on your CuratorPicker
field.
use Awcodes\Curator\View\Components\CuratorPicker;use Awcodes\Curator\PathGenerators\DatePathGenerator;Â public function register(){ CuratorPicker::make('image') ->pathGenerator(DatePathGenerator::class);}
DefaultPathGenerator
will save files in disk/directory.
DatePathGenerator
will save files in disk/directory/Y/m/d.
UserPathGenerator
will save files in disk/directory/user-auth-identifier
You are also free to use your own Path Generators by implementing the
PathGenerator
interface on your own classes.
use Awcodes\Curator\PathGenerators;Â class CustomPathGenerator implements PathGenerator{ public function getPath(?string $baseDir = null): string { return ($baseDir ? $baseDir . '/' : '') . 'my/custom/path'; }}
To render your media in a table Curator comes with a CuratorColumn
which has the same methods as Filament's
ImageColumn.
CuratorColumn::make('featured_image') ->size(40)
For multiple images you can control the number of images shown, the ring size and the overlap.
CuratorColumn::make('product_pictures') ->ring(2) // options 0,1,2,4 ->overlap(4) // options 0,2,3,4 ->limit(3),
If you are using a relationship to store your media then you will encounter n+1 issues on the column. In order to prevent this you should modify your table query to eager load the relationship.
For example when using the admin panel in your ListResource
protected function getTableQuery(): Builder{ return parent::getTableQuery()->with(['featured_image', 'product_pictures']);}
Curations are a way to create custom sizes and focal points for your images.
If you have a curation that you are constantly using you can create Presets which will be available in the Curation modal for easier reuse. After creating curation presets, they can be referenced by their key to output them in your blade files.
use Awcodes\Curator\Curations\CurationPreset;Â class ThumbnailPreset extends CurationPreset{ public function getKey(): string { return 'thumbnail'; }Â public function getLabel(): string { return 'Thumbnail'; }Â public function getWidth(): int { return 200; }Â public function getHeight(): int { return 200; }Â public function getFormat(): string { return 'webp'; }Â public function getQuality(): int { return 60; }}
Then simply register your preset in the config.
'curation_presets' => [ ThumbnailPreset::class,],
You can also change which formats are available for curations by changing the curation_formats
in the config file. These should be compatible with Intervention Image's encoding types.
'curation_formats' => [ 'jpg', 'jpeg', 'webp', 'png', 'avif',],
If you wish to disable the "Curation" tab in the Media Editor you can do so by setting tabs.display_curation
to false
in the config file. The default is true
.
'tabs' => [ 'display_curation' => false,],
If you wish to disable the "Upload New" tab in the Media Editor you can do so by setting tabs.display_upload_new
to false
in the config file. The default is true
.
'tabs' => [ 'display_upload_new' => false,],
To make it as easy as possible to output your media, Curator comes with an
<x-curator-glider>
blade component.
See Glide's quick reference for more information about Glide's options.
Special attributes
<div class="w-64 aspect-video"> <x-curator-glider class="object-cover w-auto" :media="1" glide="" fallback="" :srcset="['1024w','640w']" sizes="(max-width: 1200px) 100vw, 1024px" background="" blur="" border="" brightness="" contrast="" crop="" device-pixel-ratio="" filter="" fit="" flip="" format="" gamma="" height="" quality="" orientation="" pixelate="" sharpen="" width="" watermark-path="" watermark-width="" watermark-height="" watermark-x-offset="" watermark-y-offset="" watermark-padding="" watermark-position="" watermark-alpha="" /></div>
Glider allows for a fallback image to be used if the media item does not
exist. This can be set by passing in the fallback
attribute referencing
one of your registered GliderFallback
s.
use Awcodes\Curator\Glide\GliderFallback;Â class MyCustomGliderFallback extends GliderFallback{ public function getAlt(): string { return 'boring fallback image'; }Â public function getHeight(): int { return 640; }Â public function getKey(): string { return 'card_fallback'; }Â public function getSource(): string { return 'https://via.placeholder.com/640x420.jpg'; }Â public function getType(): string { return 'image/jpg'; }Â public function getWidth(): int { return 420; }}
Then register your fallback in the config.
'glide' => [ 'fallbacks' => [ MyCustomGliderFallback::class, ],],
Then you can reference your fallback in the blade component.
<x-curator-glider :media="1" fallback="card_fallback"/>
By default, Curator will use the route curator
when serving images through Glide. If you want to change this you can update the glide.route_path
setting in the Curator config file.
'glide' => [ 'route_path' => 'uploads',],
If you want to use your own Glide Server for handling served media with Glide you can implement the ServerFactory
interface on your own classes and set it to the config.
use League\Glide\Responses\LaravelResponseFactory;use League\Glide\Server;use League\Glide\ServerFactory;Â class CustomServerFactory implements Contracts\ServerFactory{ public function getFactory(): ServerFactory | Server { return ServerFactory::create([ 'driver' => 'imagick', 'response' => new LaravelResponseFactory(app('request')), 'source' => storage_path('app'), 'source_path_prefix' => 'public', 'cache' => storage_path('app'), 'cache_path_prefix' => '.cache', 'max_image_size' => 2000 * 2000, ]); }}
Then register your server in the config.
'glide' => [ 'server' => \App\Glide\CustomServerFactory::class,],
To make it as easy as possible to output your curations, Curator comes with an
<x-curator-curation>
blade component.
Special attributes
<x-curator-curation :media="10" curation="thumbnail" loading="lazy"/>
Since curations may or may not exist for each media item it's good to use a fallback to the glider component in your blade file so images always get rendered appropriately. This also keeps you from having to create curations for every media item, only the ones where you're trying to change the focal point, etc.
@php $preset = new ThumbnailPreset();@endphp @if ($media->hasCuration('thumbnail')) <x-curator-curation :media="$media" curation="thumbnail"/>@else <x-curator-glider class="object-cover w-auto" :media="$media" :width="$preset->getWidth()" :height="$preset->getHeight()" />@endif
If you want to use your own model for your media you can extend Curator's Media
model with your own and set it in the config.
use Awcodes\Curator\Models\Media;Â class CustomMedia extends Media{ protected $table = 'media';}
'model' => \App\Models\Cms\Media::class,
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
Adam is a full-stack web developer (with a focus on Laravel) who has been coding for close to 20 years. He is a core Filament team member as well and has authored numerous plugins for Filament such as Curator, Tiptap Editor and Table Repeater, to name a few. You can learn more about Adam on his website.