PHP code example of geekstek / filament-tree

1. Go to this page and download the library: Download geekstek/filament-tree 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/ */

    

geekstek / filament-tree example snippets


use Geekstek\FilamentTree\Forms\Components\Tree;

Tree::make('permissions')
    ->label('Permissions')
    ->helperText('Click on a parent to select all children')
    ->options([
        [
            'id' => 1,
            'label' => 'System',
            'children' => [
                ['id' => 2, 'label' => 'Users'],
                ['id' => 3, 'label' => 'Roles'],
                ['id' => 4, 'label' => 'Settings'],
            ],
        ],
        [
            'id' => 5,
            'label' => 'Content',
            'children' => [
                ['id' => 6, 'label' => 'Posts'],
                ['id' => 7, 'label' => 'Pages'],
            ],
        ],
    ])
    ->disabledOptions([3]) // Disable specific node IDs
    ->live() // Enable reactive updates
    ->columnSpanFull()

// Limit tree height to show approximately 10 rows
Tree::make('permissions')
    ->options($options)
    ->maxHeight('360px') // ~36px per row × 10 rows

// Use viewport height
Tree::make('permissions')
    ->options($options)
    ->maxHeight('50vh')

// Using integer (will be converted to pixels)
Tree::make('permissions')
    ->options($options)
    ->maxHeight(400)

use Geekstek\FilamentTree\Forms\Components\TreeSelect;

TreeSelect::make('category_id')
    ->label('Category')
    ->placeholder('Select a category...')
    ->options([
        [
            'value' => 1,
            'name' => 'Electronics',
            'children' => [
                ['value' => 2, 'name' => 'Phones'],
                ['value' => 3, 'name' => 'Laptops'],
            ],
        ],
        [
            'value' => 4,
            'name' => 'Clothing',
            'children' => [
                ['value' => 5, 'name' => 'Men'],
                ['value' => 6, 'name' => 'Women'],
            ],
        ],
    ])
    ->

// Limit dropdown height
TreeSelect::make('category_id')
    ->options($options)
    ->maxHeight('250px')

// For large datasets
TreeSelect::make('category_id')
    ->options($largeDataset)
    ->maxHeight('400px')
    ->searchable() // Enable search for easier navigation

use Geekstek\FilamentTree\Infolists\Components\TreeEntry;

TreeEntry::make('permissions')
    ->label('Assigned Permissions')
    ->options([
        [
            'id' => 1,
            'label' => 'System',
            'children' => [
                ['id' => 2, 'label' => 'Users'],
                ['id' => 3, 'label' => 'Roles'],
            ],
        ],
    ])
    ->collapsed() // Start collapsed

[
    [
        'id' => 1,           // Unique identifier
        'label' => 'Node 1', // Display text
        'children' => [      // Optional nested children
            [
                'id' => 2,
                'label' => 'Child 1',
            ],
        ],
    ],
]

[
    [
        'value' => 1,         // Unique identifier
        'name' => 'Node 1',   // Display text
        'children' => [       // Optional nested children
            [
                'value' => 2,
                'name' => 'Child 1',
            ],
        ],
    ],
]