Filament Curator

repository·5.x·Indexed 19 days ago

https://github.com/awcodes/filament-curator

A media picker and manager plugin for Filament Admin that provides a centralized interface for managing and selecting media assets. It includes the CuratorPicker field, CuratorColumn for tables, Glide integration for image transformations, and support for single and multiple media relationships. Note: This package is incompatible with Spatie Media Library.

Tokens
10.7K
Snippets
41
Records
51
Agent score
66%

What's inside filament-curator

  1. Customize Media Path Generation

    5.x

    Curator uses Path Generators to determine where files are stored. You can set these globally in the config or per instance on a CuratorPicker field.

    Built-in Generators:

    • DefaultPathGenerator: Saves in disk/directory.
    • DatePathGenerator: Saves in disk/directory/Y/m/d.
    • UserPathGenerator: Saves in disk/directory/user-auth-identifier.

    Custom Generator: Implement the PathGenerator interface to create your own logic.

    use Awcodes\Curator\PathGenerators\DatePathGenerator;
    use Awcodes\Curator\PathGenerators; // For interface
    
    // Per instance
    CuratorPicker::make('image')->pathGenerator(DatePathGenerator::class);
    
    // Custom implementation
    class CustomPathGenerator implements PathGenerator
    {
        public function getPath(?string $baseDir = null): string
        {
            return ($baseDir ? $baseDir . '/' : '') . 'my/custom/path';
        }
    }
  2. Major changes in Curator v4

    5.x

    Curator v4 introduces several breaking changes and architectural shifts compared to v3:

    Framework & Assets

    • Filament & Tailwind: Upgraded to Filament v4 and Tailwind CSS v4.
    • Asset Management: Uses Tailwind 4's new system. Curator's component CSS must still be imported via @import.
    • Dependency Removal: The cropper.js dependency has been removed, so cropper.css is no longer required.

    Configuration & Database

    • Database Table Change: The default media table has been renamed from media to curator. You must either run a migration to rename your table or override the model to point to the old table.
    • Config Structure: The configuration has been restructured into nested groups, and many keys have been renamed or relocated.
    • Environment Variables: New environment variables are now required for operation.

    Code Architecture

    • Introduction of manager classes, the Facade pattern, Enums for type safety, and DTOs (Data Transfer Objects).
  3. Register Curation Presets in v4

    5.x
    In Curator v4, CurationPreset registration has moved from the configuration file to the CurationManager class or a Service Provider. Existing CurationPreset class implementations do not need to change, but you must no longer list them in config/curator.php.
  4. Register Curator with Filament Panels

    5.x

    To use Curator within Filament Panels, you must add the CuratorPlugin to your panel's configuration. This registers the plugin's resources. Most methods are optional and will fall back to the configuration file if not explicitly provided.

    use Awcodes\Curator\CuratorPlugin;
    use Filament\Support\Icons\Heroicon
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                CuratorPlugin::make()
                    ->label('Media')
                    ->pluralLabel('Media')
                    ->navigationIcon(Heroicon::OutlinedPhoto)
                    ->navigationGroup('Content')
                    ->navigationSort(3)
                    ->showBadge(true) 
                    ->registerNavigation(true)
                    ->curations(true)
                    ->fileSwap(true),  
            ]);
    }
  5. Configure CSS for Filament Curator

    5.x

    If you are using Filament Panels and have not set up a custom theme, you must follow the Filament Docs first.

    Once a custom theme is established, add the plugin's views and styles to your theme CSS file (or your app's CSS file if using standalone packages) using @import and @source directives.

    @import '../../../../vendor/awcodes/filament-curator/resources/css/plugin.css';
    
    @source '../../../../vendor/awcodes/filament-curator/**/*.blade.php';
  6. Include Curator Modals in Standalone Forms

    5.x

    If you are using the stand-alone forms package instead of Filament Panels, you must manually include the Curator modal in your layout file. It is recommended to place this component before the closing </body> tag.

    <x-curator::modals.modal />
  7. Update Theme CSS for Tailwind 4 and Curator v4

    5.x

    Curator v4 requires specific CSS handling due to Tailwind 4's CSS-first architecture. You must update your theme's CSS file (e.g., resources/css/filament/admin/theme.css) with the following steps:

    1. Remove cropper.js imports.
    2. Import Curator's plugin CSS: This is required for component styles like .curator-picker-grid and .checkered.
    3. Add @source directives: Tell Tailwind 4 to scan Curator's Blade files and your Filament directories.
    4. Verify Vite configuration: Ensure @tailwindcss/vite is included in vite.config.js.

    Note: Filament 4 does not use tailwind.config.js by default.

    /* resources/css/filament/admin/theme.css */
    @import '../../../../vendor/filament/filament/resources/css/theme.css';
    @import '../../../../vendor/awcodes/filament-curator/resources/css/plugin.css';
    
    @source '../../../../vendor/awcodes/filament-curator/resources/**/*.blade.php';
    @source '../../../../app/Filament/**/*';
    @source '../../../../resources/views/filament/**/*';
  8. Configure Glide Server for Cloud Disks (S3/MinIO)

    5.x

    If your media is stored on a cloud disk, you must configure the Glide server to use the correct Flysystem driver.

    Critical Configuration Notes:

    • source: Must point to the cloud disk's Flysystem driver.
    • source_path_prefix: Usually an empty string '' for cloud disks because the driver is already rooted at the bucket. A mismatched prefix is the most common cause of broken images.
    • cache: Keep this on a fast local disk to avoid repeated cloud requests.
    use Awcodes\Curator\Facades\Glide;
    use Illuminate\Support\Facades\Storage;
    
    Glide::serverConfig([
        'response' => new LaravelResponseFactory(app('request')),
        'source' => Storage::disk('s3')->getDriver(),
        'source_path_prefix' => '', 
        'cache' => Storage::disk('local')->getDriver(),
        'cache_path_prefix' => '.cache',
        'max_image_size' => 2000 * 2000,
    ]);
  9. Configure Media Relationships

    5.x

    Curator supports both single and multiple media relationships.

    Single Relationship

    Form:

    CuratorPicker::make('featured_image_id')->relationship('featured_image', 'id')

    Model:

    public function featuredImage(): BelongsTo
    {
        return $this->belongsTo(Media::class, 'featured_image_id', 'id');
    }

    Multiple Relationship

    Form:

    CuratorPicker::make('product_picture_ids')
        ->multiple()
        ->relationship('product_pictures', 'id')
        ->orderColumn('order')

    Model:

    public function productPictures(): BelongsToMany
    {
        return $this->belongsToMany(Media::class, 'media_post', 'post_id', 'media_id')
            ->withPivot('order')
            ->orderBy('order');
    }
  10. Use a Custom Media Model

    5.x

    You can extend the default Media model and tell Curator to use your custom class via the configuration file.

    use Awcodes\Curator\Models\Media;
    
    class CustomMedia extends Media
    {
        protected $table = 'media';
    }
    
    // In config/curator.php
    'model' => \App\Models\Cms\Media::class,
  11. Upgrade requirements for Filament Curator v4

    5.x

    To upgrade to Curator v4, your environment must meet the following minimum requirements:

    • PHP: 8.2 or higher
    • Laravel: 11.28 or higher (required by Filament 4)
    • Filament: 4.0 or higher
    • Tailwind CSS: 4.0 or higher