PHP code example of novius / filament-relation-nested

1. Go to this page and download the library: Download novius/filament-relation-nested library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

novius / filament-relation-nested example snippets


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(),
            ]);
    }
}

class MenuResource extends Resource
{
    public static function getRelations(): array
    {
        return [
            // ...
            MenuItemsTreeRelationManager::class,
        ];
    }
}

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'),

                // ....
            ]);
    }
}
sh
php artisan filament:assets