PHPackages                             adrolli/filament-select-tree - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. adrolli/filament-select-tree

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

adrolli/filament-select-tree
============================

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

3.x-dev(11mo ago)50MITPHPPHP ^8.1

Since Jun 9Pushed 11mo agoCompare

[ Source](https://github.com/adrolli/filament-select-tree)[ Packagist](https://packagist.org/packages/adrolli/filament-select-tree)[ Docs](https://github.com/codewithdennis/filament-select-tree)[ GitHub Sponsors](https://github.com/CodeWithDennis)[ RSS](/packages/adrolli-filament-select-tree/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (3)Used By (0)

Filament Select Tree
====================

[](#filament-select-tree)

> ATTENTION: This is just a temporary fork to test Filament 4 compatibility. Stick with the Original package `codewithdennis/filament-select-tree` to stay with a maintained package after Filament 4 was released.

[![Latest Version on Packagist](https://camo.githubusercontent.com/a6c1bed8af3fcd3037a7ac8f4f06b05ef65ef2879d43c13cabbb5b8e96a766a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64657769746864656e6e69732f66696c616d656e742d73656c6563742d747265652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codewithdennis/filament-select-tree)[![Total Downloads](https://camo.githubusercontent.com/af431823329515f811c4cea866605e5f434fd6825695186d6fe89d4fc94aa505/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64657769746864656e6e69732f66696c616d656e742d73656c6563742d747265652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codewithdennis/filament-select-tree)

This 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 building selection dropdowns with various customization options.

[![thumbnail](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/thumbnail.jpg)](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/thumbnail.jpg)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require adrolli/filament-select-tree
```

```
php artisan filament:assets
```

Relationships
-------------

[](#relationships)

Use the tree for a `BelongsToMany` relationship

```
SelectTree::make('categories')
    ->relationship('categories', 'name', 'parent_id')
```

Use the tree for a `BelongsTo` relationship

```
SelectTree::make('category_id')
    ->relationship('category', 'name', 'parent_id')
```

Custom Query
------------

[](#custom-query)

Customize the parent query

```
SelectTree::make('categories')
    ->relationship(relationship: 'categories', titleAttribute: 'name', parentAttribute: 'parent_id', modifyQueryUsing: fn($query) => $query));
```

Customize the child query

```
SelectTree::make('categories')
    ->relationship(relationship: 'categories', titleAttribute: 'name', parentAttribute: 'parent_id', modifyChildQueryUsing: fn($query) => $query));
```

Methods
-------

[](#methods)

Set a custom placeholder when no items are selected

```
->placeholder(__('Please select a category'))
```

Enable the selection of groups

```
->enableBranchNode()
```

Customize the label when there are zero search results

```
->emptyLabel(__('Oops, no results have been found!'))
```

Display the count of children alongside the group's name

```
->withCount()
```

Keep the dropdown open at all times

```
->alwaysOpen()
```

Set nodes as dependent

```
->independent(false)
```

Expand the tree with selected values (only works if field is dependent)

```
->expandSelected(false)
```

Set the parent's null value to -1, allowing you to use -1 as a sentinel value (default = null)

```
->parentNullValue(-1)
```

All groups will be opened to this level

```
->defaultOpenLevel(2)
```

Specify the list's force direction. Options include: auto (default), top, and bottom.

```
->direction('top')
```

Display individual leaf nodes instead of the main group when all leaf nodes are selected

```
->grouped(false)
```

Hide the clearable icon

```
->clearable(false)
```

Activate the search functionality

```
->searchable();
```

Disable specific options in the tree

```
->disabledOptions([2, 3, 4])
```

Hide specific options in the tree

```
->hiddenOptions([2, 3, 4])
```

Allow soft deleted items to be displayed

```
->withTrashed()
```

Specify a different key for your model. For 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

```
->withKey('code')
```

Store fetched models for additional functionality

```
->storeResults()
```

Now you can access the results in `disabledOptions` or `hiddenOptions`

```
->disabledOptions(function ($state, SelectTree $component) {
    $results = $component->getResults();
})
```

By 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 explicitly set the selection type, use:

```
->multiple(false)
```

you can change the tree key with the following method.

```
->treeKey('my-cool-tree')
```

If 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).

```
use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;
use CodeWithDennis\FilamentSelectTree\SelectTree;
```

```
->filters([
    Filter::make('tree')
        ->form([
            SelectTree::make('category')
                ->relationship('categories', 'name', 'parent_id')
                ->enableBranchNode()
                ->multiple(false)
                ->prepend([
                    'name' => 'Uncategorized Records',
                    'value' => -1,
                    'parent' => null, // optional
                    'disabled' => false, // optional
                    'hidden' => false, // optional
                    'children' => [], // optional
                ])
        ])
        ->query(function (Builder $query, array $data) {
            return $query->when($data['categories'], function (Builder $query, $categories) {
                if (collect($categories)->contains('-1')) {
                    $query->whereDoesntHave('categories');
                }
                return $query->orWhereHas('categories',
                    fn(Builder $query) => $query->whereIn('id', $categories));
            });
        })
])
```

Filters
-------

[](#filters)

Use the tree in your table filters. Here's an example to show you how.

```
use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;
use CodeWithDennis\FilamentSelectTree\SelectTree;
```

```
->filters([
    Filter::make('tree')
        ->form([
            SelectTree::make('categories')
                ->relationship('categories', 'name', 'parent_id')
                ->independent(false)
                ->enableBranchNode(),
        ])
        ->query(function (Builder $query, array $data) {
            return $query->when($data['categories'], function ($query, $categories) {
                return $query->whereHas('categories', fn($query) => $query->whereIn('id', $categories));
            });
        })
        ->indicateUsing(function (array $data): ?string {
            if (! $data['categories']) {
                return null;
            }

            return __('Categories') . ': ' . implode(', ', Category::whereIn('id', $data['categories'])->get()->pluck('name')->toArray());
        })
])
```

Screenshots
-----------

[](#screenshots)

[![example-1](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-1.jpg)](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-1.jpg)[![example-2](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-2.jpg)](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-2.jpg)[![example-3](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-3.jpg)](https://raw.githubusercontent.com/CodeWithDennis/filament-select-tree/3.x/resources/images/example-3.jpg)

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [CodeWithDennis](https://github.com/CodeWithDennis)
- [Dipson88](https://github.com/dipson88/treeselectjs)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance52

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 70.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

2

Last Release

334d ago

Major Versions

3.x-dev → 4.0-beta12025-06-18

PHP version history (2 changes)3.x-devPHP ^8.1

4.0-beta1PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/40421928?v=4)[Alf Drollinger](/maintainers/adrolli)[@adrolli](https://github.com/adrolli)

---

Top Contributors

[![CodeWithDennis](https://avatars.githubusercontent.com/u/23448484?v=4)](https://github.com/CodeWithDennis "CodeWithDennis (260 commits)")[![lotestudio](https://avatars.githubusercontent.com/u/1052691?v=4)](https://github.com/lotestudio "lotestudio (21 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (16 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (13 commits)")[![buzkall](https://avatars.githubusercontent.com/u/5702?v=4)](https://github.com/buzkall "buzkall (10 commits)")[![saade](https://avatars.githubusercontent.com/u/14329460?v=4)](https://github.com/saade "saade (9 commits)")[![gpibarra](https://avatars.githubusercontent.com/u/21188012?v=4)](https://github.com/gpibarra "gpibarra (7 commits)")[![markvaneijk](https://avatars.githubusercontent.com/u/1925388?v=4)](https://github.com/markvaneijk "markvaneijk (5 commits)")[![iotron](https://avatars.githubusercontent.com/u/50877415?v=4)](https://github.com/iotron "iotron (5 commits)")[![ariaieboy](https://avatars.githubusercontent.com/u/15873972?v=4)](https://github.com/ariaieboy "ariaieboy (3 commits)")[![mgkimsal](https://avatars.githubusercontent.com/u/75154?v=4)](https://github.com/mgkimsal "mgkimsal (3 commits)")[![A909M](https://avatars.githubusercontent.com/u/119125167?v=4)](https://github.com/A909M "A909M (3 commits)")[![gp-lnuff](https://avatars.githubusercontent.com/u/169065476?v=4)](https://github.com/gp-lnuff "gp-lnuff (2 commits)")[![adrolli](https://avatars.githubusercontent.com/u/40421928?v=4)](https://github.com/adrolli "adrolli (2 commits)")[![gehrisandro](https://avatars.githubusercontent.com/u/25097194?v=4)](https://github.com/gehrisandro "gehrisandro (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![mohamedsabil83](https://avatars.githubusercontent.com/u/10126040?v=4)](https://github.com/mohamedsabil83 "mohamedsabil83 (2 commits)")[![awcodes](https://avatars.githubusercontent.com/u/3596800?v=4)](https://github.com/awcodes "awcodes (1 commits)")[![smiliyas](https://avatars.githubusercontent.com/u/13122679?v=4)](https://github.com/smiliyas "smiliyas (1 commits)")[![OccTherapist](https://avatars.githubusercontent.com/u/28587659?v=4)](https://github.com/OccTherapist "OccTherapist (1 commits)")

---

Tags

laraveltreefilamentCodeWithDennisfilament-select-tree

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/adrolli-filament-select-tree/health.svg)

```
[![Health](https://phpackages.com/badges/adrolli-filament-select-tree/health.svg)](https://phpackages.com/packages/adrolli-filament-select-tree)
```

###  Alternatives

[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

320392.1k17](/packages/codewithdennis-filament-select-tree)[pboivin/filament-peek

Full-screen page preview modal for Filament

253319.6k12](/packages/pboivin-filament-peek)[dotswan/filament-map-picker

Easily pick and retrieve geo-coordinates using a map-based interface in your Filament applications.

124139.3k2](/packages/dotswan-filament-map-picker)[creagia/filament-code-field

A Filamentphp input field to edit or view code data.

58289.3k3](/packages/creagia-filament-code-field)[ralphjsmit/laravel-filament-components

A collection of reusable components for Filament.

10972.2k2](/packages/ralphjsmit-laravel-filament-components)[swisnl/filament-backgrounds

Beautiful backgrounds for Filament auth pages

54149.2k6](/packages/swisnl-filament-backgrounds)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
