{"id":22189921,"url":"https://github.com/saade/filament-adjacency-list","last_synced_at":"2025-10-25T14:11:13.438Z","repository":{"id":189027625,"uuid":"679804100","full_name":"saade/filament-adjacency-list","owner":"saade","description":"A Filament package to manage adjacency lists (aka trees).","archived":false,"fork":false,"pushed_at":"2025-03-03T11:08:39.000Z","size":4238,"stargazers_count":83,"open_issues_count":12,"forks_count":16,"subscribers_count":4,"default_branch":"3.x","last_synced_at":"2025-04-08T03:48:01.366Z","etag":null,"topics":["adjacency-list","filament","form-builder","laravel","tree"],"latest_commit_sha":null,"homepage":"https://filamentphp.com/plugins/saade-adjacency-list","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saade.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["saade"]}},"created_at":"2023-08-17T16:52:26.000Z","updated_at":"2025-03-25T19:15:40.000Z","dependencies_parsed_at":"2023-08-17T23:43:00.687Z","dependency_job_id":"f155754c-732e-4d85-bb28-512d003e29ec","html_url":"https://github.com/saade/filament-adjacency-list","commit_stats":{"total_commits":39,"total_committers":7,"mean_commits":5.571428571428571,"dds":0.5641025641025641,"last_synced_commit":"66b21ad2bc473f1260efe2379b66d352bfa4a12e"},"previous_names":["saade/filament-adjacency-list"],"tags_count":15,"template":false,"template_full_name":"filamentphp/plugin-skeleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saade%2Ffilament-adjacency-list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saade%2Ffilament-adjacency-list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saade%2Ffilament-adjacency-list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saade%2Ffilament-adjacency-list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saade","download_url":"https://codeload.github.com/saade/filament-adjacency-list/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248617651,"owners_count":21134196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adjacency-list","filament","form-builder","laravel","tree"],"created_at":"2024-12-02T11:40:22.678Z","updated_at":"2025-10-25T14:11:13.433Z","avatar_url":"https://github.com/saade.png","language":"PHP","funding_links":["https://github.com/sponsors/saade"],"categories":[],"sub_categories":[],"readme":"# Filament Adjacency List\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/saade/filament-adjacency-list.svg?style=flat-square)](https://packagist.org/packages/saade/filament-adjacency-list)\n[![Total Downloads](https://img.shields.io/packagist/dt/saade/filament-adjacency-list.svg?style=flat-square)](https://packagist.org/packages/saade/filament-adjacency-list)\n\nA Filament package to manage adjacency lists (aka trees).\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/saade/filament-adjacency-list/3.x/art/cover.png\" alt=\"Banner\" style=\"width: 100%; max-width: 800px;\" /\u003e\n\u003c/p\u003e\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require saade/filament-adjacency-list\n```\n\n\u003e [!IMPORTANT]\n\u003e In an effort to align with Filament's theming methodology you will need to use a custom theme to use this plugin.\n\u003e\u003e  If you have not set up a custom theme and are using a Panel follow the instructions in the Filament Docs first. The following applies to both the Panels Package and the standalone Forms package.\n\n1. Add the plugin's views to your `tailwind.config.js` file.\n\n```js\ncontent: [\n    ...\n    '\u003cpath-to-vendor\u003e/saade/filament-adjacency-list/resources/**/*.blade.php',\n]\n```\n\n2. Rebuild your custom theme.\n\n```sh\nnpm run build\n```\n\n## Usage\n\n```php\nuse Saade\\FilamentAdjacencyList\\Forms\\Components\\AdjacencyList;\n\nAdjacencyList::make('subjects')\n    -\u003eform([\n        Forms\\Components\\TextInput::make('label')\n            -\u003erequired(),\n    ])\n```\n\n## Configuration\n### Customizing the `label` key used to display the item's label\n```php\nAdjacencyList::make('subjects')\n    -\u003elabelKey('name')          // defaults to 'label'\n```\n\n### Customizing the `children` key used to gather the item's children.\n\u003e **Note:** This is only used when not using relationships.\n```php\nAdjacencyList::make('subjects')\n    -\u003echildrenKey('children')   // defaults to 'children'\n```\n\n### Customizing the `MaxDepth` of the tree.\n```php\nAdjacencyList::make('subjects')\n    -\u003emaxDepth(2)               // defaults to -1 (unlimited depth)\n```\n\n### Triggering an action or opening a URL when clicking on an item.\n```php\nAdjacencyList::make('subjects')\n    -\u003eitemAction('edit') // or view, delete, moveUp, indent etc ...\n    -\u003eitemUrl(\n        fn (array $item) =\u003e YourResource::getUrl('view', ['record' =\u003e $item['id']]) // for example\n    )\n```\n\n### Creating items without a modal.\n```php\nAdjacencyList::make('subjects')\n    -\u003emodal(false)      // defaults to true\n```\n\n### Disabling creation, edition, deletion, reordering, moving, and indenting.\n```php\nAdjacencyList::make('subjects')\n    -\u003eaddable(false)\n    -\u003eeditable(false)\n    -\u003edeletable(false)\n    -\u003ereorderable(false)\n    -\u003emoveable(false)\n    -\u003eindentable(false)\n```\n\n### Customizing actions\n```php\nuse Filament\\Forms\\Actions\\Action;\n\nAdjacencyList::make('subjects')\n    -\u003eaddAction(fn (Action $action): Action =\u003e $action-\u003eicon('heroicon-o-plus')-\u003ecolor('primary'))\n    -\u003eaddChildAction(fn (Action $action): Action =\u003e $action-\u003ebutton())\n    -\u003eeditAction(fn (Action $action): Action =\u003e $action-\u003eicon('heroicon-o-pencil'))\n    -\u003edeleteAction(fn (Action $action): Action =\u003e $action-\u003erequiresConfirmation())\n    -\u003ereorderAction(fn (Action $action): Action =\u003e $action-\u003eicon('heroicon-o-arrow-path-rounded-square'))\n```\n\n## Relationships\nIn this example, we'll be creating a Ticketing system, where tickets can be assigned to a department, and departments have subjects.\n\n### Building the relationship\n```php\n// App/Models/Department.php\n\nclass Department extends Model\n{\n    public function subjects(): HasMany\n    {\n        return $this-\u003ehasMany(Subject::class)-\u003ewhereNull('parent_id')-\u003ewith('children')-\u003eorderBy('sort');\n    }\n}\n```\n\n```php\n// App/Models/Subject.php\n\nclass Subject extends Model\n{\n    protected $fillable ['parent_id', 'name', 'sort']; // or whatever your columns are\n\n    public function children(): HasMany\n    {\n        return $this-\u003ehasMany(Subject::class, 'parent_id')-\u003ewith('children')-\u003eorderBy('sort');\n    }\n}\n```\n\nNow you've created a nested relationship between departments and subjects.\n\n### Using the relationship\n```php\n// App/Filament/Resources/DepartmentResource.php\n\nAdjacencyList::make('subjects')\n    -\u003erelationship('subjects')          // Define the relationship\n    -\u003elabelKey('name')                  // Customize the label key to your model's column\n    -\u003echildrenKey('children')           // Customize the children key to the relationship's method name\n    -\u003eform([                            // Define the form\n        Forms\\Components\\TextInput::make('name')\n            -\u003elabel(__('Name'))\n            -\u003erequired(),\n    ]);\n```\n\nThat's it! Now you're able to manage your adjacency lists using relationships.\n\n### Working with Staudenmeir's Laravel Adjacency List\nThis package also supports [Staudenmeir's Laravel Adjacency List](https://github.com/staudenmeir/laravel-adjacency-list) package.\n\nFirst, install the package:\n```bash\ncomposer require staudenmeir/laravel-adjacency-list:\"^1.0\"\n```\n\n1. Use the `HasRecursiveRelationships` trait in your model, and override the default path separator.\n\n```php\n// App/Models/Department.php\n\nclass Department extends Model\n{\n    use \\Staudenmeir\\LaravelAdjacencyList\\Eloquent\\HasRecursiveRelationships;\n\n    public function getPathSeparator()\n    {\n        return '.children.';\n    }\n}\n```\n\nIf you're already using the HasRecursiveRelationships trait for other parts of your application, it's probably not a good idea to change your model's path separator, since it can break other parts of your application. Instead, you can add as many path separators as you want:\n\n```php\nclass Department extends Model\n{\n    use \\Staudenmeir\\LaravelAdjacencyList\\Eloquent\\HasRecursiveRelationships;\n\n    public function getCustomPaths()\n    {\n        return [\n            [\n                'name' =\u003e 'tree_path',\n                'column' =\u003e 'id',\n                'separator' =\u003e '.children.',\n            ],\n        ];\n    }\n}\n```\n\n2. Use the `relationship` method to define the relationship:\n\n```php\nAdjacencyList::make('subdepartments')\n    -\u003erelationship('descendants')   // or 'descendantsAndSelf', 'children' ...\n    -\u003ecustomPath('tree_path')       // if you're using custom paths\n```\n\nThat's it! Now you're able to manage your adjacency lists using relationships.\n\n### Customizing the query\n```php\nAdjacencyList::make('subdepartments')\n    -\u003erelationship('descendants', fn (Builder $query): Builder =\u003e $query-\u003ewhere('enabled', 1))\n```\n\n### Ordering\nIf your application needs to order the items in the list, you can use the `orderColumn` method:\n\n```php\nAdjacencyList::make('subdepartments')\n    -\u003eorderColumn('sort')   // or any other column\n```\n\n## Widget\n\nThe `AdjacencyListWidget` can be used to render a tree for any model with a recursive child relationship (including many-to-many graph relationships, using Staudenmeir's HasGraphRelationships trait).\n\nThe simplest use case is ...\n\n```php\nclass DepartmentTreeWidget extends AdjacencyListWidget\n{    \n    protected static string $relationshipName = 'descendantsAndSelf';\n\n    // If you're using a widget on an Edit or View page, the plugin will automatically set the $record for you.\n    // However, you're free to override this method to customize the record.\n    public function getModel(): Model | string | null\n    {\n        return Department::query()-\u003ewhere(['is_root' =\u003e true])-\u003efirst();\n    }\n\n    // You can configure the widget using the same methods as the form component.\n    protected function adjacencyList(AdjacencyList $adjacencyList): AdjacencyList\n    {\n        return $adjacencyList\n            -\u003elabel('Foo')\n            -\u003eeditable()\n            -\u003elabelKey('nombre')\n            -\u003echildrenKey('hijos');\n    }\n}\n\n```\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Saade](https://github.com/saade)\n- [Ryan Chandler's Navigation Plugin](https://github.com/ryangjchandler/filament-navigation) for his work on the tree UI and complex tree actions.\n- [Hugh](https://github.com/cheesegrits) for his help on supporting trees/ graphs relationships.\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/sponsors/saade\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/saade/filament-adjacency-list/3.x/art/sponsor.png\" alt=\"Sponsor Saade\" style=\"width: 100%; max-width: 800px;\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaade%2Ffilament-adjacency-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaade%2Ffilament-adjacency-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaade%2Ffilament-adjacency-list/lists"}