Skip to content

Extensibility & Customization ​

Sanchaya resolves its main behavior from configuration, so production apps can replace the default Eloquent models, authorization policy, and file-operation action classes without editing package files.

Replace Models and Policy

Use custom models when you need extra casts, relationships, scopes, observers, or table names. Extend the package models so the file manager keeps the expected relationships and helpers.

php
// config/filament-sanchaya.php
'model' => \App\Models\MediaFile::class,
'attachment_model' => \App\Models\MediaAttachment::class,
'policy' => \App\Policies\MediaFilePolicy::class,
php
namespace App\Models;

use DP0\Sanchaya\Models\SanchayaFile;

class MediaFile extends SanchayaFile
{
    protected $table = 'sanchaya_files';

    protected $casts = [
        'metadata' => 'array',
    ];
}

When both default models are replaced, publish and own the migrations in your application. Sanchaya only auto-loads package migrations for the default file or attachment models.

Override Action Classes

Each configured action is resolved from Laravel's container. Create a class with the same public method contract as the action you are replacing; extending the shipped class is the safest starting point.

php
// config/filament-sanchaya.php
'actions' => [
    'delete' => [
        'enabled' => true,
        'label' => 'Delete',
        'icon' => 'heroicon-m-trash',
        'class' => \App\Actions\MyCustomDeleteAction::class,
    ],
],
php
namespace App\Actions;

use DP0\Sanchaya\Actions\DeleteAction;
use DP0\Sanchaya\Models\SanchayaFile;

class MyCustomDeleteAction extends DeleteAction
{
    public function execute(SanchayaFile $item): bool
    {
        // Add audit logging, external cleanup, or business checks here.

        return parent::execute($item);
    }
}
Config keyDefault classMethods used by the manager
actions.download.classDownloadActionexecute($file), bulk($items)
actions.create_folder.classCreateFolderActionexecute($name, $disk, $parentId)
actions.rename.classRenameActionexecute($item, $newName)
actions.move.classMoveActionexecute($item, $destinationId, $destinationDisk)
actions.copy.classCopyActionexecute($item, $destinationId, $destinationDisk)
actions.delete.classDeleteActionexecute($item), bulk($items), restore($item), forceDeleteTrashed($item)

The preview action has configurable visibility, label, and icon, but it does not resolve a backend action class.

Released under the MIT License.