Relation Nested
Plugin to manage nested relationships using the Nested Set model.
Author:
Novius
Documentation
#Introduction
This Laravel Filament package allows you to manage relation that uses the kalnoy/nestedset in your Laravel Filament admin panel.
#Requirements
- PHP >= 8.2
- Laravel Filament >= 5
- Laravel Framework >= 11.0
#Installation
composer require novius/filament-relation-nested
Publish Filament assets
php artisan filament:assets
#Usage
#Relation Manager
First create a RelationManager for your filament resource that have a relation to a model that uses nestedset package:
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Novius\FilamentRelationNested\Filament\Actions\FixTreeAction;
use Novius\FilamentRelationNested\Filament\Resources\RelationManagers\TreeRelationManager;
class MenuItemsTreeRelationManager extends TreeRelationManager
{
// Define the relationship name
protected static string $relationship = 'items';
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('title'),
])
->pluralModelLabel('Menu items')
->recordTitleAttribute('title')
->headerActions([
CreateAction::make(),
// Add the FixTreeAction if you want an action that fix the nestedset tree
FixTreeAction::make(),
])
->actions([
EditAction::make(),
DeleteAction::make(),
]);
}
}
Then add it to your resource
class MenuResource extends Resource
{
public static function getRelations(): array
{
return [
// ...
MenuItemsTreeRelationManager::class,
];
}
}
#TreeColumn
You can use this column in a filament table on a model that uses the nestedset package. This will display a column which, when sorting is this column, will give an idea of the tree.
use CodeWithDennis\FilamentSelectTree\SelectTree;
use Exception;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Resources\Resource;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Novius\FilamentRelationNested\Filament\Tables\Columns\TreeColumn;
use Novius\LaravelFilamentMenu\Enums\LinkType;
use Novius\LaravelFilamentMenu\Facades\MenuManager;
use Novius\LaravelFilamentMenu\Filament\Resources\MenuItemResource\Pages\CreateMenuItem;
use Novius\LaravelFilamentMenu\Filament\Resources\MenuItemResource\Pages\EditMenuItem;
use Novius\LaravelFilamentMenu\Filament\Resources\MenuItemResource\RelationManagers\MenuItemsRelationManager;
use Novius\LaravelFilamentMenu\Models\Menu;
use Novius\LaravelFilamentMenu\Models\MenuItem;
use Novius\LaravelLinkable\Filament\Forms\Components\Linkable;
use Wiebenieuwenhuis\FilamentCodeEditor\Components\CodeEditor;
class MenuItemResource extends Resource
{
public static function table(Table $table): Table
{
return $table
// This will disable the pagination when the table is sorted by the _lft field
->paginated(fn (Table $table) => ! empty($table->getSortColumn()) && $table->getSortColumn() !== '_lft')
// This will default sort the table on the _lft field
->defaultSort('_lft')
->columns([
TreeColumn::make('_lft'),
// ....
]);
}
}
#Lint
Run php-cs with:
composer run-script lint
#Contributing
Contributions are welcome! Leave an issue on Github, or create a Pull Request.
#Licence
This package is under GNU Affero General Public License v3 or (at your option) any later version.
The author
Novius is a French web agency specializing in the development of tailor-made web applications with Laravel.
We design robust, maintainable and business-oriented tools, with particular attention paid to the developer experience and the sustainability of projects. Our Filament plugins are used in production on customer projects and are designed to meet concrete needs, proven in the field.
From the same author
Action Preview
Action to preview a resource before saving or publishing it.
Author:
Novius
Slug
Plugin to generate and manage slugs automatically.
Author:
Novius
Page Manager
Plugin to manage pages and structured content from the admin panel.
Author:
Novius
Redirect Manager
Plugin to manage URL redirections directly from the admin panel.
Author:
Novius
Featured Plugins
A selection of plugins curated by the Filament team
Custom Dashboards
Let your users build and share their own dashboards with a drag-and-drop interface. Define your data sources in PHP and let them do the rest.
Filament
Advanced Tables (formerly Filter Sets)
Supercharge your tables with powerful features like user-customizable views, quick filters, multi-column sorting, advanced table searching, convenient view management, and more. Compatible with Resource Panel Tables, Relation Managers, Table Widgets, and Table Builder!
Kenneth Sese
Custom Fields
Eliminate custom field migrations forever. Let your users create and manage form fields directly in Filament admin panels with 20+ built-in field types, validation, and zero database changes.
Relaticle