Sanchaya v1.0

Filament Sanchaya

A premium, Filament-native file manager and media picker for Laravel.

In Nepali, Sanchaya (सञ्चय) means the act of gathering or amassing something valuable over time. This package follows that idea: your files are gathered in one place, indexed in your database, and managed with a familiar Filament experience.

🗂️

Full File Manager

Folder tree, grid/list views, cursor pagination, toolbar with search & filters.

🖼️

SanchayaPicker Field

Drop-in Filament form field for single or multi-file selection with group-based persistence.

☁️

Multi-Disk

Switch between any configured Laravel filesystem disk at runtime.

🔒

Authorization

Laravel Gate policy controls who can rename, move, copy, delete, or download.

📎

Model Attachments

Polymorphic group-based attachments via the HasSanchayaFiles trait.

Requirements

  • PHP ^8.4
  • Laravel ^13.0
  • Filament ^5.0

Installation

1. Install via Composer

composer require dp0/filament-sanchaya

2. Run the Interactive Installer

php artisan sanchaya:install

The installer will prompt you to:

  • Publish config/filament-sanchaya.php
  • Publish and run migrations
  • Choose your default storage disk

3. Filament Custom Theme Requirement

⚠️
Required — not optional

Sanchaya uses custom styling and Tailwind CSS utility classes. Without a custom Filament theme, components and colors will not render correctly.

If you do not have a custom theme configured for your Filament panel, generate one:

php artisan make:filament-theme

Since Filament uses Tailwind CSS v4, add the package's views directory to your custom theme's main CSS file (usually resources/css/filament/admin/theme.css) using the @source directive. This tells Tailwind to scan the package views for utility classes:

@source "../../../../vendor/dp0/filament-sanchaya/resources/views";

Then make sure your panel actually uses that theme by pointing viteTheme() at it in your panel provider — otherwise your theme (and the package styles) will never be loaded:

public function panel(Panel $panel): Panel
{
    return $panel
        ->viteTheme('resources/css/filament/admin/theme.css')
        ->plugins([
            SanchayaPlugin::make(),
        ]);
}

Finally, compile your assets using your asset bundler:

npm run dev # or npm run build

Manual Publishing

php artisan vendor:publish --tag=sanchaya-config
php artisan vendor:publish --tag=sanchaya-migrations
php artisan vendor:publish --tag=sanchaya-views
php artisan migrate

Configuration

Edit config/filament-sanchaya.php after publishing.

return [
    // Eloquent model for file records
    'model' => \DP0\Sanchaya\Models\SanchayaFile::class,

    // Gate policy for file operations. null = no authorization.
    'policy' => \DP0\Sanchaya\Policies\SanchayaFilePolicy::class,

    // true = soft deletes (recoverable); false = hard delete
    'soft_deletes' => true,

    'allowed_disks' => null,

    'default_disk' => env('SANCHAYA_DEFAULT_DISK', 'public'),

    'file' => [
        'max_file_size'       => 10240,  // KB — 10 MB
        'accepted_file_types' => [],     // e.g. ['image/*']
    ],
];

Config Reference

KeyDefaultDescription
modelSanchayaFileEloquent class for file records.
attachment_modelSanchayaAttachmentEloquent class for pivot.
policySanchayaFilePolicyGate policy controlling file operations.
soft_deletestrueWhether deletes are recoverable.
default_diskpublicDisk shown when the manager opens.

Plugin Registration

Register in your Filament panel provider:

use DP0\Sanchaya\SanchayaPlugin;

public function panel(Panel $panel): Panel
{
    return $panel->plugins([
        SanchayaPlugin::make(),
    ]);
}

Fluent Options

SanchayaPlugin::make()
    ->navigationLabel('Media')
    ->navigationIcon('heroicon-o-folder')
    ->navigationGroup('Content')
    ->navigationSort(20);

Authorization & Policy

Sanchaya ships with SanchayaFilePolicy which defaults all gates to true.

💡
Custom Policy

The service provider calls Gate::policy() during boot — but only if you haven't already registered one.

// config/filament-sanchaya.php
'policy' => \App\Policies\MyFilePolicy::class,

File Manager

The file manager is registered automatically at /admin/sanchaya.

AreaFeatures
ToolbarDisk switcher, search bar, MIME-type filter, sort controls.
SidebarFull recursive folder tree for quick navigation.
Detail panelName, size, type, disk, path, and a preview/URL.
Bulk selectionMulti-select for bulk delete and ZIP download.

SanchayaPicker Form Field

use DP0\Sanchaya\Forms\Components\SanchayaPicker;

Single File

SanchayaPicker::make('hero_image')
    ->saveInGroup('hero')
    ->allowedTypes(['image']);

Multiple Files

SanchayaPicker::make('gallery')
    ->multiple()
    ->maxFiles(12)
    ->saveInGroup('gallery');

Method Reference

MethodDescription
multiple()Enable multi-select mode
maxFiles(int)Cap the number of selected files
allowedTypes(array)image, video, audio, document
saveInGroup(string)Attachment group name

HasSanchayaFiles Trait

use DP0\Sanchaya\Traits\HasSanchayaFiles;

class Post extends Model
{
    use HasSanchayaFiles;
}

Reading Attachments

// All files in group
$gallery = $post->sanchayaFiles('gallery');

// First file's URL
$url = $post->sanchayaUrl('hero');

Writing Attachments

// Sync a group to an exact set of IDs
$post->syncSanchayaFiles([10, 11, 12], 'gallery');

SanchayaFile Model

Accessors

AccessorTypeDescription
$file->display_namestringOriginal name or file name
$file->url?stringPublic or signed URL
$file->human_sizestringe.g. "2.4 MB"

Relationships

$file->parent();    // BelongsTo folder
$file->children();  // HasMany files/folders

Database Schema

sanchaya_files

ColumnTypeNotes
parent_idbigint FKSelf-reference; null = root
typeenumfile or folder
diskstringFilesystem disk name
pathstringRelative path on disk

Built-in Actions

ActionDescription
CreateFolderCreates a folder record
RenameRenames file/folder (moves bytes)
MoveMoves tree to new parent or disk
CopyDeep-copies file or folder tree
DeleteSoft- or force-deletes records/bytes
DownloadStreams file or ZIPs selection

Extensibility

Replace an Action Class

// config/filament-sanchaya.php
'actions' => [
    'delete' => [
        'enabled' => true,
        'class' => \App\Actions\MyDelete::class,
    ],
],

Troubleshooting

🚨
Broken Styles or Layout

If layouts appear unstyled or colors are missing, ensure you have a custom theme configured. Because Filament uses Tailwind CSS v4, you must add the package views directory to your custom theme's main CSS file using the @source directive: @source "../../../../vendor/dp0/filament-sanchaya/resources/views"; and rebuild your assets (npm run build).

⚠️
403 Forbidden

The active Gate policy is returning false. Debug with Gate::inspect().

ℹ️
Empty Manager

Confirm your disk is in config/filesystems.php and allowed_disks config.