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
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
| Key | Default | Description |
|---|---|---|
model | SanchayaFile | Eloquent class for file records. |
attachment_model | SanchayaAttachment | Eloquent class for pivot. |
policy | SanchayaFilePolicy | Gate policy controlling file operations. |
soft_deletes | true | Whether deletes are recoverable. |
default_disk | public | Disk 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);
File Manager
The file manager is registered automatically at /admin/sanchaya.
| Area | Features |
|---|---|
| Toolbar | Disk switcher, search bar, MIME-type filter, sort controls. |
| Sidebar | Full recursive folder tree for quick navigation. |
| Detail panel | Name, size, type, disk, path, and a preview/URL. |
| Bulk selection | Multi-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
| Method | Description |
|---|---|
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
| Accessor | Type | Description |
|---|---|---|
$file->display_name | string | Original name or file name |
$file->url | ?string | Public or signed URL |
$file->human_size | string | e.g. "2.4 MB" |
Relationships
$file->parent(); // BelongsTo folder
$file->children(); // HasMany files/folders
Database Schema
sanchaya_files
| Column | Type | Notes |
|---|---|---|
parent_id | bigint FK | Self-reference; null = root |
type | enum | file or folder |
disk | string | Filesystem disk name |
path | string | Relative path on disk |
Built-in Actions
| Action | Description |
|---|---|
CreateFolder | Creates a folder record |
Rename | Renames file/folder (moves bytes) |
Move | Moves tree to new parent or disk |
Copy | Deep-copies file or folder tree |
Delete | Soft- or force-deletes records/bytes |
Download | Streams file or ZIPs selection |
Extensibility
Replace an Action Class
// config/filament-sanchaya.php
'actions' => [
'delete' => [
'enabled' => true,
'class' => \App\Actions\MyDelete::class,
],
],
Troubleshooting
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).
The active Gate policy is returning false. Debug with Gate::inspect().
Confirm your disk is in config/filesystems.php and allowed_disks config.