- How do I install and set up filament-select-tree in a Laravel Filament 4.x project?
- Run `composer require codewithdennis/filament-select-tree:4.x` and execute `php artisan filament:assets` to compile assets. The package is designed for Filament 4.x (use the 3.x branch for Filament 3.x). No database migrations are required—just configure the field in your Filament form or table.
- Can I use this package for a BelongsToMany relationship, like assigning multiple categories to a post?
- Yes, the package supports BelongsToMany relationships out of the box. Use `SelectTree::make('categories')->relationship('categories', 'name', 'parent_id')` to enable multi-select functionality. The tree will render as a hierarchical dropdown where users can select multiple nodes.
- What Laravel and Filament versions does this package support?
- The package is compatible with Laravel 10/11 and Filament 3.x/4.x. For Filament 3.x, use the `3.x` branch of the package. PHP 8.5+ is required. Always check the [GitHub repo](https://github.com/CodeWithDennis/filament-select-tree) for the latest version compatibility.
- How do I customize the tree query for non-standard parent-child relationships (e.g., using a custom attribute like `parent_code`)?
- Use the `modifyQueryUsing` or `modifyChildQueryUsing` methods to customize the query. For example, `SelectTree::make('departments')->relationship('departments', 'name', 'parent_code')` will use `parent_code` instead of `parent_id`. You can also pass a closure to further refine the query logic.
- Does the package support soft-deleted models (e.g., withTrashed())? If so, how do I handle orphaned nodes?
- Yes, the package supports soft-deleted models. Use `withTrashed()` in your query to include deleted nodes. Orphaned nodes (nodes without a parent) will appear as root-level items. For strict behavior, use `strictNullParentRootNodes()` to prevent promoting orphaned nodes to the root.
- Will this package work with large hierarchies (e.g., 5,000+ nodes)? Are there performance considerations?
- For large hierarchies, performance depends on your server and client-side rendering. The package loads the entire tree structure at once, which may impact performance. Test with realistic datasets and consider optimizing queries (e.g., `select()` only needed columns) or implementing lazy-loading via custom JavaScript.
- Can I use this package for non-Eloquent data, like API responses or in-memory arrays?
- Yes, the package supports custom queries via the `query()` method. Pass an array or use a closure to return data in the format `[{ id, name, parent_id }, ...]`. This makes it flexible for non-database hierarchies, such as API responses or dynamically generated trees.
- How do I implement a tree filter in a Filament table column (e.g., to filter posts by category)?
- Use the `SelectTree::make()` field in a Filament table column filter. Configure it with the same relationship or query as your form field. For example, `SelectTree::make('category_id')->relationship('category', 'name', 'parent_id')` will create a hierarchical filter dropdown in your table.
- What happens if I update Filament to a new major version? Will this package break?
- The package is tightly coupled to Filament’s internals, so major Filament updates may require updates to this package. Monitor Filament’s upgrade guide and check the package’s [GitHub issues](https://github.com/CodeWithDennis/filament-select-tree/issues) for compatibility announcements. If needed, fork or patch the package for critical fixes.
- Are there alternatives to this package for hierarchical selects in Filament? When would I choose another solution?
- Alternatives include custom Vue.js components (e.g., using `vue-treeselect`) or simpler nested select fields. Choose this package if you need deep integration with Filament’s form/table system, Eloquent relationship support, and built-in customization (e.g., strict root nodes, query scopes). Opt for a custom solution if you require advanced client-side features (e.g., drag-and-drop) or minimal dependency risk.