PHP code example of saade / filament-adjacency-list
1. Go to this page and download the library: Download saade/filament-adjacency-list 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/ */
saade / filament-adjacency-list example snippets
use Filament\Forms\Components\TextInput;
use Saade\FilamentAdjacencyList\Forms\Components\AdjacencyList;
AdjacencyList::make('menu')
->schema([
TextInput::make('label')
->
class Menu extends Model
{
protected function casts(): array
{
return [
'items' => 'array',
];
}
}
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
class Category extends Model
{
use HasRecursiveRelationships;
protected $fillable = ['parent_id', 'name', 'sort'];
}
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasGraphRelationships;
class Node extends Model
{
use HasGraphRelationships;
public function getPivotTableName(): string
{
return 'edges';
}
}
AdjacencyList::make('items')
->addable(false)
->editable(false)
->deletable(false)
->reorderable(false) // dragging
->moveable(false) // the move up and move down buttons
->indentable(false) // the indent and outdent buttons
use Filament\Forms\Components\TextInput;
use Saade\FilamentAdjacencyList\Forms\Components\AdjacencyList;
use Saade\FilamentAdjacencyList\Widgets\AdjacencyListWidget;
class CategoryTreeWidget extends AdjacencyListWidget
{
protected function adjacencyList(AdjacencyList $adjacencyList): AdjacencyList
{
return $adjacencyList
->labelKey('name')
->orderColumn('sort')
->schema([
TextInput::make('name')->
protected function getModel(): ?Model
{
return Category::query()->whereNull('parent_id')->first();
}