### Install 15web/filament-tree Package Source: https://github.com/15web/filament-tree/blob/main/README.md Installs the filament-tree package using Composer. This is the first step to integrate tree functionality into your Filament project. ```bash composer require 15web/filament-tree ``` -------------------------------- ### Eloquent Model Setup for Tree Functionality Source: https://context7.com/15web/filament-tree/llms.txt Configures an Eloquent model to use the tree functionality by applying the `NodeTrait` and `InteractsWithTree` traits. It also defines the attribute used for displaying node labels and an optional caption. ```php description; } } ``` -------------------------------- ### Publish Filament Tree Views Source: https://github.com/15web/filament-tree/blob/main/README.md Publishes the view files for the Filament Tree package. This allows for deep customization of the package's front-end presentation if needed. ```bash php artisan vendor:publish --tag="filament-tree-views" ``` -------------------------------- ### Publish Filament Tree Configuration Source: https://github.com/15web/filament-tree/blob/main/README.md Publishes the configuration files for the Filament Tree package to your application. This allows you to customize settings like parent deletion restrictions and root deletion restrictions. ```bash php artisan vendor:publish --tag="filament-tree-config" ``` -------------------------------- ### Create Filament Tree Page Source: https://github.com/15web/filament-tree/blob/main/README.md This command generates a new Filament Tree page. You will be prompted to enter the name of the page and the associated model class. This sets up the basic structure for managing hierarchical data. ```shell php artisan make:filament-tree-page ``` -------------------------------- ### Publish Filament Tree Translations Source: https://github.com/15web/filament-tree/blob/main/README.md Publishes the translation files for the Filament Tree package. This enables you to customize the language strings used within the package for different locales. ```bash php artisan vendor:publish --tag="filament-tree-translations" ``` -------------------------------- ### Define Infolist Entries for Tree Page Source: https://github.com/15web/filament-tree/blob/main/README.md Configures additional information to be displayed next to each node label in the tree. This method returns an array of Infolist entries, allowing for dynamic labels and display of boolean values like 'is_published'. ```php public static function getInfolistColumns(): array { return [ TextEntry::make('description')->label(fn(Category $record, Get $get) => $record->description !== null ? 'Desc' : ''), IconEntry::make('is_published')->boolean()->label(''), ]; } ``` -------------------------------- ### Configure Basic Filament Tree Page Source: https://context7.com/15web/filament-tree/llms.txt Extends the `TreePage` class to configure a tree structure for a Category model. It defines the model, navigation icon, page title, and forms for creating and editing nodes. It also includes optional infolist columns to display metadata like slug and published status. ```php required() ->maxLength(255), TextInput::make('slug') ->required() ->unique(ignoreRecord: true) ->maxLength(255), ]; } /** * Define form fields for editing existing nodes */ public static function getEditForm(): array { return [ TextInput::make('title') ->required() ->maxLength(255), TextInput::make('slug') ->required() ->unique(ignoreRecord: true) ->maxLength(255), Toggle::make('is_published') ->label('Published'), TextInput::make('description') ->nullable() ->maxLength(500), ]; } /** * Display additional info next to each node label */ public static function getInfolistColumns(): array { return [ TextEntry::make('slug') ->label('Slug') ->color('gray'), IconEntry::make('is_published') ->boolean() ->label(''), ]; } } ``` -------------------------------- ### Publish Configuration File Source: https://context7.com/15web/filament-tree/llms.txt Publishes the configuration file for the filament-tree package. This allows for customization of delete restrictions and form behavior, such as preventing the deletion of parent nodes or root nodes. ```bash php artisan vendor:publish --tag="filament-tree-config" ``` -------------------------------- ### Generate Filament Tree Page with Artisan Command Source: https://context7.com/15web/filament-tree/llms.txt Generates a new Filament Tree page using an Artisan command. This command creates a page that extends `TreePage` and is configured for a specified model. ```bash php artisan make:filament-tree-page CategoryTree Category ``` -------------------------------- ### Publish Translations and Views Source: https://context7.com/15web/filament-tree/llms.txt Publishes the language files and blade views for the filament-tree package. This allows for customization of labels, messages, and the visual appearance of the tree interface. ```bash # Publish language files php artisan vendor:publish --tag="filament-tree-translations" # Publish blade views php artisan vendor:publish --tag="filament-tree-views" ``` -------------------------------- ### Configure Scoped Footer Menu Tree Page Source: https://context7.com/15web/filament-tree/llms.txt Configures a Filament `TreePage` for the footer menu, using the `MenuItem` model. It returns a scoped query for `menu_id = 2` to manage only footer menu items. The create and edit forms include fields for title and URL. ```php 2]); } public static function getCreateForm(): array { return [ \Filament\Forms\Components\TextInput::make('title')->required(), \Filament\Forms\Components\TextInput::make('url')->required()->url(), ]; } public static function getEditForm(): array { return [ \Filament\Forms\Components\TextInput::make('title')->required(), \Filament\Forms\Components\TextInput::make('url')->required()->url(), ]; } } ``` -------------------------------- ### Register Filament Tree Service Provider Source: https://context7.com/15web/filament-tree/llms.txt Registers the Filament Tree service provider in the application's bootstrap file. This makes the package's functionalities available throughout your application. ```php // bootstrap/providers.php 1]); } public static function getCreateForm(): array { return [ TextInput::make('title')->required(), TextInput::make('url')->required()->url(), ]; } public static function getEditForm(): array { return [ TextInput::make('title')->required(), TextInput::make('url')->required()->url(), ]; } } ``` -------------------------------- ### Prepare Eloquent Model with Nested Set Integration Source: https://github.com/15web/filament-tree/blob/main/README.md Integrates the InteractsWithTree trait into an Eloquent model that already uses the Kalnoy/Nestedset package. This enables tree management capabilities. ```php false, // Prevent deletion of root nodes (even if allow-delete-parent is true) 'allow-delete-root' => false, // Show parent selection dropdown in the edit form // When false, users can still reorder via drag-and-drop 'show-parent-select-while-edit' => true, ]; ``` -------------------------------- ### Database Migration for Nested Set Columns Source: https://context7.com/15web/filament-tree/llms.txt Adds the necessary columns for the Nested Set pattern to a database table using a Laravel migration. This enables hierarchical data management for the tree structure. ```php nestedSet(); // Adds _lft, _rgt, and parent_id columns }); } public function down(): void { Schema::table('categories', function (Blueprint $table) { $table->dropNestedSet(); }); } }; ``` ```bash php artisan migrate ``` -------------------------------- ### Define Create Form Fields for Tree Page Source: https://github.com/15web/filament-tree/blob/main/README.md Defines the form fields that will be used when creating a new record in the tree structure. It utilizes Filament's TextInput component for 'title' and 'slug', ensuring they are required. The 'slug' field also has a unique constraint. ```php public static function getCreateForm(): array { return [ TextInput::make('title')->required(), TextInput::make('slug')->required()->unique(ignoreRecord: true), ]; } ``` -------------------------------- ### Add Nested Set Columns Migration Source: https://github.com/15web/filament-tree/blob/main/README.md Creates a new migration to add the necessary columns for the nested set structure to a database table. This is required when the Eloquent model does not have prior Nested Set integration. ```php return new class extends Migration { public function up(): void { Schema::table('awesome_model_table', function (Blueprint $table) { $table->nestedSet(); }); } ``` -------------------------------- ### Create ParentSelect Form Component Source: https://context7.com/15web/filament-tree/llms.txt Creates a searchable dropdown for selecting parent nodes in a form. It automatically excludes invalid options such as the current record and its descendants. This component is useful for managing hierarchical relationships in forms. ```php 2]); } } ``` -------------------------------- ### Filament Tree Translation Strings Source: https://context7.com/15web/filament-tree/llms.txt Contains translation strings for the filament-tree package in English. These strings are used for labels, messages, and user feedback within the tree management interface. ```php 'Parent tree item', 'item_moved' => 'Tree item moved', 'descendant_error' => 'Node must not be a descendant', 'fix_tree' => 'Fix tree', 'tree_fixed' => 'Tree has been fixed successfully', 'empty_tree' => 'Tree is empty. Create your first node.', ]; ``` -------------------------------- ### Define Edit Form Fields for Tree Page Source: https://github.com/15web/filament-tree/blob/main/README.md Defines the form fields for editing an existing record in the tree structure. It includes fields for 'title', 'slug', 'is_published' (using a Toggle component), and an optional 'description'. The 'slug' field maintains its unique constraint. ```php public static function getEditForm(): array { return [ TextInput::make('title')->required(), TextInput::make('slug')->required()->unique(ignoreRecord: true), Toggle::make('is_published'), TextInput::make('description')->nullable(), ]; } ``` -------------------------------- ### Define Tree Caption in Model Source: https://github.com/15web/filament-tree/blob/main/README.md Allows you to specify a secondary line of text to be displayed below the main label of each node in the tree. This is achieved by adding a `getTreeCaption` method to your Eloquent model that returns the desired attribute. ```php public function getTreeCaption(): ?string { return $this->description; } ``` -------------------------------- ### Define Scope Attributes in Model for Scoped Trees Source: https://github.com/15web/filament-tree/blob/main/README.md Specifies the attributes used for scoping tree data within a single table. This is useful when a table contains multiple distinct trees (e.g., header menu and footer menu). The `getScopeAttributes` method should return an array of attribute names. ```php public function getScopeAttributes(): array { return ['menu_id']; } ``` -------------------------------- ### Define Scoped Tree Model Source: https://context7.com/15web/filament-tree/llms.txt Defines a `MenuItem` model that uses the `NodeTrait` and `InteractsWithTree` traits for hierarchical data management. It specifies fillable attributes and defines the `getScopeAttributes` method to return an array of attributes used for scoping tree operations, such as 'menu_id'. ```php 1])->fixTree(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.