{"id":16461836,"url":"https://github.com/codewithdennis/filament-select-tree","last_synced_at":"2026-01-19T15:05:58.786Z","repository":{"id":193680559,"uuid":"689287488","full_name":"CodeWithDennis/filament-select-tree","owner":"CodeWithDennis","description":"The multi-level select field lets you pick one or multiple options from a list that is neatly organized into different levels.","archived":false,"fork":false,"pushed_at":"2025-04-13T08:44:11.000Z","size":960,"stargazers_count":269,"open_issues_count":5,"forks_count":42,"subscribers_count":4,"default_branch":"3.x","last_synced_at":"2025-05-08T18:02:59.456Z","etag":null,"topics":["field","filament","filament-plugin","filamentphp","laravel","php","select","select-tree","tree","tree-structure"],"latest_commit_sha":null,"homepage":"","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/CodeWithDennis.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,"zenodo":null},"funding":{"github":"CodeWithDennis"}},"created_at":"2023-09-09T10:42:26.000Z","updated_at":"2025-05-06T02:33:35.000Z","dependencies_parsed_at":"2023-09-09T12:31:07.514Z","dependency_job_id":"909a8944-7f86-4516-8df8-a8b927c15cb2","html_url":"https://github.com/CodeWithDennis/filament-select-tree","commit_stats":{"total_commits":208,"total_committers":13,"mean_commits":16.0,"dds":0.5961538461538461,"last_synced_commit":"85dce452bb0fd072f6c39b41f0da92a769e8706d"},"previous_names":["codewithdennis/filament-select-tree"],"tags_count":57,"template":false,"template_full_name":"filamentphp/plugin-skeleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeWithDennis%2Ffilament-select-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeWithDennis%2Ffilament-select-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeWithDennis%2Ffilament-select-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeWithDennis%2Ffilament-select-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeWithDennis","download_url":"https://codeload.github.com/CodeWithDennis/filament-select-tree/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254254039,"owners_count":22039792,"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":["field","filament","filament-plugin","filamentphp","laravel","php","select","select-tree","tree","tree-structure"],"created_at":"2024-10-11T11:09:35.863Z","updated_at":"2025-05-15T01:05:42.247Z","avatar_url":"https://github.com/CodeWithDennis.png","language":"PHP","funding_links":["https://github.com/sponsors/CodeWithDennis"],"categories":[],"sub_categories":[],"readme":"# Filament Select Tree\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/codewithdennis/filament-select-tree.svg?style=flat-square)](https://packagist.org/packages/codewithdennis/filament-select-tree)\n[![Total Downloads](https://img.shields.io/packagist/dt/codewithdennis/filament-select-tree.svg?style=flat-square)](https://packagist.org/packages/codewithdennis/filament-select-tree)\n\nThis package adds a dynamic select tree field to your Laravel / Filament application, allowing you to create interactive hierarchical selection dropdowns based on relationships. It's handy for\nbuilding selection dropdowns with various customization options.\n\n![thumbnail](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/thumbnail.jpg)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require codewithdennis/filament-select-tree\n```\n\n```bash\nphp artisan filament:assets\n```\n\n## Relationships\n\nUse the tree for a `BelongsToMany` relationship\n\n```php\nSelectTree::make('categories')\n    -\u003erelationship('categories', 'name', 'parent_id')\n```\n\nUse the tree for a `BelongsTo` relationship\n\n```php\nSelectTree::make('category_id')\n    -\u003erelationship('category', 'name', 'parent_id')\n```\n\n## Custom Query\n\nCustomize the parent query\n\n```php\nSelectTree::make('categories')\n    -\u003erelationship(relationship: 'categories', titleAttribute: 'name', parentAttribute: 'parent_id', modifyQueryUsing: fn($query) =\u003e $query));\n```\n\nCustomize the child query\n\n```php\nSelectTree::make('categories')\n    -\u003erelationship(relationship: 'categories', titleAttribute: 'name', parentAttribute: 'parent_id', modifyChildQueryUsing: fn($query) =\u003e $query));\n```\n\n## Methods\n\nSet a custom placeholder when no items are selected\n\n```php\n-\u003eplaceholder(__('Please select a category'))\n```\n\nEnable the selection of groups\n\n```php\n-\u003eenableBranchNode()\n```\n\nCustomize the label when there are zero search results\n\n```php\n-\u003eemptyLabel(__('Oops, no results have been found!'))\n```\n\nDisplay the count of children alongside the group's name\n\n```php\n-\u003ewithCount()\n```\n\nKeep the dropdown open at all times\n\n```php\n-\u003ealwaysOpen()\n```\n\nSet nodes as dependent\n\n```php\n-\u003eindependent(false)\n```\n\nExpand the tree with selected values (only works if field is dependent)\n\n```php\n-\u003eexpandSelected(false)\n```\n\nSet the parent's null value to -1, allowing you to use -1 as a sentinel value (default = null)\n\n```php\n-\u003eparentNullValue(-1)\n```\n\nAll groups will be opened to this level\n\n```php\n-\u003edefaultOpenLevel(2)\n```\n\nSpecify the list's force direction. Options include: auto (default), top, and bottom.\n\n```php\n-\u003edirection('top')\n```\n\nDisplay individual leaf nodes instead of the main group when all leaf nodes are selected\n\n```php\n-\u003egrouped(false)\n```\n\nHide the clearable icon\n\n```php\n-\u003eclearable(false)\n```\n\nActivate the search functionality\n\n```php\n-\u003esearchable();\n```\n\nDisable specific options in the tree\n\n```php\n-\u003edisabledOptions([2, 3, 4])\n```\n\nHide specific options in the tree\n\n```php\n-\u003ehiddenOptions([2, 3, 4])\n```\n\nAllow soft deleted items to be displayed\n\n```php\n-\u003ewithTrashed()\n```\n\nSpecify a different key for your model.\nFor example: you have id, code and parent_code. Your model uses id as key, but the parent-child relation is established between code and parent_code\n\n```php\n-\u003ewithKey('code')\n```\n\nStore fetched models for additional functionality\n\n```php\n-\u003estoreResults()\n```\n\nNow you can access the results in `disabledOptions` or `hiddenOptions`\n\n```php\n-\u003edisabledOptions(function ($state, SelectTree $component) {\n    $results = $component-\u003egetResults();\n})\n```\n\nBy default, the type of selection in the tree (single or multiple) is determined by the relationship type: `BelongsTo` for single selection and `BelongsToMany` for multiple selection. If you want to\nexplicitly set the selection type, use:\n\n```php\n-\u003emultiple(false)\n```\n\nBy default, the tree key (wire key) will be a random generated value, you can change this with the following method.\n\n```php\n-\u003etreeKey('my-cool-tree')\n```\n\nIf you need to prepend an item to the tree menu, use the `prepend` method. This method accepts an array or a closure. It is useful when the tree-select is used as a filter (see example below).\n\n```php\nuse Filament\\Tables\\Filters\\Filter;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse CodeWithDennis\\FilamentSelectTree\\SelectTree;\n```\n\n```php\n-\u003efilters([\n    Filter::make('tree')\n        -\u003eform([\n            SelectTree::make('category')\n                -\u003erelationship('categories', 'name', 'parent_id')\n                -\u003eenableBranchNode()\n                -\u003emultiple(false)\n                -\u003eprepend([\n                    'name' =\u003e 'Uncategorized Records',\n                    'value' =\u003e -1,\n                    'parent' =\u003e null, // optional\n                    'disabled' =\u003e false, // optional\n                    'hidden' =\u003e false, // optional\n                    'children' =\u003e [], // optional\n                ])\n        ])\n        -\u003equery(function (Builder $query, array $data) {\n            $categories = [(int) $data['category']];\n            \n            return $query-\u003ewhen($data['category'], function (Builder $query, $categories) {\n                if($data['category'] === -1){\n                    return $query-\u003ewhereDoesntHave('categories');\n                }\n                \n                return $query-\u003ewhereHas('categories', fn(Builder $query) =\u003e $query-\u003ewhereIn('id', $categories));\n            });\n        })\n])\n```\n\n## Filters\n\nUse the tree in your table filters. Here's an example to show you how.\n\n```bash\nuse Filament\\Tables\\Filters\\Filter;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse CodeWithDennis\\FilamentSelectTree\\SelectTree;\n```\n\n```php\n-\u003efilters([\n    Filter::make('tree')\n        -\u003eform([\n            SelectTree::make('categories')\n                -\u003erelationship('categories', 'name', 'parent_id')\n                -\u003eindependent(false)\n                -\u003eenableBranchNode(),\n        ])\n        -\u003equery(function (Builder $query, array $data) {\n            return $query-\u003ewhen($data['categories'], function ($query, $categories) {\n                return $query-\u003ewhereHas('categories', fn($query) =\u003e $query-\u003ewhereIn('id', $categories));\n            });\n        })\n        -\u003eindicateUsing(function (array $data): ?string {\n            if (! $data['categories']) {\n                return null;\n            }\n\n            return __('Categories') . ': ' . implode(', ', Category::whereIn('id', $data['categories'])-\u003eget()-\u003epluck('name')-\u003etoArray());\n        })\n])\n```\n\n## Screenshots\n\n![example-1](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-1.jpg)\n![example-2](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-2.jpg)\n![example-3](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-3.jpg)\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- [CodeWithDennis](https://github.com/CodeWithDennis)\n- [Dipson88](https://github.com/dipson88/treeselectjs)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewithdennis%2Ffilament-select-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodewithdennis%2Ffilament-select-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewithdennis%2Ffilament-select-tree/lists"}