Aller au contenu
← Retour aux projets

Filament Master Detail

#This is my package filament-master-detail

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package adds a master–detail layout for Filament resources. It renders a table on the left and the selected record’s page on the right, with pagination and deep links preserved.

#Installation

You can install the package via Composer:

composer require eightynine/filament-master-detail

Publish and run the migrations:

php artisan vendor:publish --tag="filament-master-detail-migrations"
php artisan migrate

Publish the config file:

php artisan vendor:publish --tag="filament-master-detail-config"

Optionally, publish the views:

php artisan vendor:publish --tag="filament-master-detail-views"

#Configuration

After publishing, you can customize settings in config/master-detail.php.

This is the contents of the published config file (currently no options; reserved for future use):

return [
];

#Usage

  1. Register the plugin in your Filament Panel provider and set the scopes (resources to use in the master–detail view):
use App\Providers\Filament\AdminPanelProvider; // or your custom Panel provider
use Filament\Panel;
use EightyNine\MasterDetail\MasterDetailPlugin;
use App\Filament\Resources\CustomerResource; // example
use App\Filament\Resources\OrderResource;    // example

class AdminPanelProvider extends AdminPanelProvider
{
	public function panel(Panel $panel): Panel
	{
		return $panel
			// ... other panel config
			->plugin(MasterDetailPlugin::make()
            ->scopes([
                OrderResource::class
            ]));
	}
}
  1. In your target Filament Resource, implement getMasterDetailColumns() to define the table columns used in the master–detail view:
use Filament\Tables; 
use Filament\Tables\Columns\TextColumn;

public function getMasterDetailColumns(): array
{
	return [
		TextColumn::make('id')->label('ID')->sortable(),
		TextColumn::make('name')->searchable()->toggleable(),
		// add more columns as needed
	];
}

Optional (advanced):

  • Customize the base query used by the master–detail table by adding a static method to your Resource:
public static function modifyMasterDetailQuery(\Illuminate\Database\Eloquent\Builder $query)
{
	return $query->latest();
}

#Testing

composer test

#Changelog

Please see CHANGELOG for more information on what has changed recently.

#Contributing

Please see CONTRIBUTING for details.

#Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

#Credits

#License

The MIT License (MIT). Please see License File for more information.

Nouvelle version disponible.