A media picker plugin for Filament Admin.
Install the package via composer.
composer require awcodes/filament-curator
(optional) Publish the config.
php artisan vendor:publish --tag=filament-curator-config
Install Filament Curator into your app. This will publish the necessary migration and Filament resources.
php artisan curator:install
By default Curator will generate image sizes for each uploaded image based on the sizes setting in the config file. If you want to disable image sizes completely then set the sizes key to an empty array.
'sizes' => [],
If you need to regenerate all of your image sizes, for instance you add or remove a size from your config you can do so with the following Artisan command.
php artisan curator:regenerate-thumbnails
By default in the Media Resource table the disk icon is set to display a cloud if the disk is either 'Cloudinary' or 's3'. If you would like to extend or change this you can do so in the filament-curator.php
config file.
'cloud_disks' => ['cloudinary', 's3', 'your_cloud_provider'];
Include the MediaPicker button in your forms to trigger the modal and either select an existing image or upload a new one.
use FilamentCurator\Forms\Components\MediaPicker;
MediaPicker::make(string $fieldName)
->label(string $customLabel)
Media can also be related to models by simply adding the relationship to your model.
use FilamentCurator\Models\Media;
public function ogImage(): HasOne
{
return $this->hasOne(Media::class, 'id', 'og_image');
}
To retrieve different sizes urls, Curator's Media model comes with a helper that takes in a size and returns the url for you. Sizes are based on your config settings.
If a size doesn't exist in your config, then it will return the full size image url.
// Assuming a relationship on a Meta model for ogImage...
$meta->ogImage->getSizeUrl('thumbnail');
$meta->ogImage->getSizeUrl('medium');
$meta->ogImage->getSizeUrl('large');
If you need additional functionality you can extend Curator's Media model with your own and updating the 'model' setting in the config file with your model.
use FilamentCurator\Models\Media as CuratorMedia;
class Media extends CuratorMedia
{
// ... custom methods and properties
}
If you need addtional functionality from your resources you can extend Curator's Resources and views with your own and updating the 'media_resource' setting in the config file with your own resources.
use FilamentCurator\Resrouces\MediaResource as CuratorMediaResource;
class MediaResource extends CuratorMediaResource
{
// ... custom methods and properties
}
If you are using a custom theme for Filament you will need to add this plugin's views to your Tailwind CSS config.
content: [
...
"./vendor/awcodes/filament-curator/resources/views/**/*.blade.php",
],
This projects follow the Semantic Versioning guidelines.
Copyright (c) 2022 Adam Weston and contributors
Licensed under the MIT license, see LICENSE.md for details.