finnwiel/shazzoo-media

A Laravel + Filament plugin extension for filament-curator. That adds conversions and new views.

v1.1.7 2025-05-16 10:12 UTC

This package is auto-updated.

Last update: 2025-05-16 10:13:23 UTC


README

License Packagist Version Laravel Filament PHP

A Laravel + Filament plugin that extends Filament Curator with custom media conversion logic and a customized media model.

Installation

You can install the package via composer then run the installation command:

composer require finnwiel/shazzoo-media

If you installed Curator before Shazzoo Media, you’ll need to remove Curator’s media table migration manually before running the install command.

php artisan shazzoo_media:install

Note: This plugin will install curator for you but you will have to do some of the setup. Like installing CropperJS and using a custom filament theme for styling. If you have not set up a custom theme and are using a Panel follow the instructions in the Filament Docs first.

npm install -D cropperjs

Import the plugin's stylesheet and cropperjs' stylesheet into your theme's css file.

@import '<path-to-vendor>/awcodes/filament-curator/resources/css/plugin.css';

Add the plugin's views to your tailwind.config.js file.

content: [
        './vendor/awcodes/filament-curator/resources/**/*.blade.php',
        './vendor/finnwiel/shazzoo-media/resources/views/vendor/curator/components/**/*.blade.php',
]

Usage

Global settings

The plugins settings can be managed through the config file

php artisan vendor:publish --tag=shazzoo_media-config

Note: This plugin will also change some of curators settings, you can still manage curators setting but they may not work with Shazzoo Media

Filament Panels

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')
                    ->navigationLabel('Media Library')
                    ->resource(MediaResource::class) // use FinnWiel\ShazzooMedia\Resources\MediaResource;
                    ->registerNavigation(true)
                    ->navigationCountBadge(true)   
            ])
}

Picker field

Shazzoo Media adds a conversions method to the picker field, this method accepts an array. The conversions will subsequently be set in the database for each array item. Shazzoo Media will also create the conversion image.

ShazzooMediaCuratorPicker::make('featured_image_id')
                    ->conversions(['thumbnail']),

To generate actually set the conversions in the database you need to add a trait to the create and edit classes of your resource.

use FinnWiel\ShazzooMedia\Traits\HandlesConversions;

class CreatePost extends CreateRecord
{
    use HandlesConversions;

    protected static string $resource = PostResource::class;
}

Conversions

Conversions are set in config/shazzoo_media.php in the conversions array. To add or remove conversions change the array with the same structure.

'conversions' => [
    'profile' => ['width' => 80,'height' => 80],
    'thumbnail' => ['width' => 200,'height' => 200],
    'medium' => ['width' => 400,'height' => 400],
    'large' => ['width' => 600,'height' => 600],
],

So adding a new conversion called small would look like this:

'conversions' => [
    'profile' => ['width' => 80,'height' => 80],
    'thumbnail' => ['width' => 200,'height' => 200],
    'medium' => ['width' => 400,'height' => 400],
    'large' => ['width' => 600,'height' => 600],
    'small' => ['width' => 100,'height' => 100],
],

You can also edit the values of conversions, this can even be done when some conversions have already been made. Just be sure to run the php artisan media:conversions:regenerate command. This will regenerate the conversions to the new sizes.

Artisan commands

The Shazzoo Media plugin uses some artisan commands.

Commands Tags Uses
media:clear - Clears your image files from the storage folder.
media:conversions:clear-db id Clears conversion(s) in the database.
media:conversions:set-db id append Sets conversion(s) in the databse.
media:conversions:generate id all only Generates the conversions for the images.
media:conversions:regenerate id only Regenerates the conversions for the images.
media:conversions:list - Lists out all image conversions

Policies & Tenancy

Policies

The Shazzoo Media library doesn't use a policy by default but lets you publish a policy template.

php artisan vendor:publish --tag=shazzoo-media-policy

This will publish a policy file to App/Policies/MediaPolicy.php the policy should be registered automatically by the plugin. The published file will be a blank policy, you will need to add your own rules. Also make sure that media_policies is set to true in the config/shazzoo_media.php.

Tenancy

Shazzoo Media does not include tenancy support out of the box, but it provides configuration hooks to help you integrate tenancy into your media handling.

To enable tenancy, follow these steps:

  1. In your config/shazzoo_media.php:
'tenant_scoping' => [
    'enabled' => true, 
    'field' => 'tenant_id',
    'resolver' => fn () => auth()->guard()->user()->tenant_id, 
],

Note: Enabling tenant scoping does not implement tenancy for you. These settings are a starting point — you'll need to integrate tenancy using your own logic or a plugin (e.g., Spatie Multitenancy).

  • enabled: Enables tenant isolation.
  • field: The database column used for tenant association.
  • resolver: A callable function that returns the current tenant’s ID.
  1. Add the chosen field to your media table

Update your media and users table:

$table->unsignedBigInteger('tenant_id')->nullable()->index();