Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Select Tree Laravel Package

codewithdennis/filament-select-tree

Dynamic select tree field for Laravel Filament that renders hierarchical dropdowns from relationships or custom queries. Supports BelongsTo and BelongsToMany, parent/child attributes, and customizable parent/child query scopes with optional strict root behavior.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Hierarchical Data Visualization: The package excels at representing nested, relational data (e.g., categories, taxonomies, or organizational structures) in a user-friendly, interactive tree format. This aligns well with Laravel/Filament applications requiring multi-level selections (e.g., content management, e-commerce categories, or role-based access).
  • Filament Integration: Built specifically for Filament 3.x/4.x, it leverages Filament’s form and table components, ensuring consistency with the admin panel’s design system (e.g., styling, validation, and localization).
  • Relationship-Centric: Optimized for Eloquent relationships (BelongsTo, BelongsToMany), reducing boilerplate for querying hierarchical data. Supports custom queries for non-relational use cases.
  • Extensibility: Offers hooks for custom tree structures (getTreeUsing), dynamic filtering, and pre/post-processing, making it adaptable to edge cases (e.g., hybrid data sources or non-database hierarchies).

Integration Feasibility

  • Low Friction: Composer installation + filament:assets command is standard for Filament packages. No complex migrations or database changes required.
  • Dependency Alignment: Compatible with Laravel 10/11 and Filament 3.x/4.x, with explicit support for PHP 8.5+. Dependents (e.g., treeselectjs) are well-maintained.
  • ORM Agnostic: While Eloquent-focused, the package can work with custom arrays or closures, enabling use with non-Eloquent data (e.g., API responses or in-memory structures).
  • UI/UX Parity: Inherits Filament’s styling and accessibility standards, ensuring the tree widget blends seamlessly with existing forms/tables.

Technical Risk

  • Filament Version Lock: Tight coupling to Filament’s internals (e.g., form components, table filters) may require updates if Filament’s API changes. Monitor Filament’s upgrade guide for breaking changes.
  • Performance at Scale: Heavy hierarchies (e.g., >10,000 nodes) may impact client-side rendering or server-side query performance. Test with realistic datasets.
  • Custom Logic Complexity: Advanced features (e.g., getTreeUsing with dynamic data) require careful implementation to avoid N+1 queries or memory leaks. Use storeResults() judiciously.
  • Edge Cases: Features like strictNullParentRootNodes or withTrashed introduce subtle query behavior. Validate with test data covering orphaned nodes, soft deletes, and filtered states.

Key Questions

  1. Data Model Compatibility:

    • Are the target hierarchies stored in Eloquent models with standard parent_id fields, or will custom mappings (e.g., parent_code) be needed?
    • How will the package handle non-standard relationships (e.g., polymorphic, many-to-many with pivot tables)?
  2. Performance Requirements:

    • What is the expected depth/size of the largest hierarchy? Are there plans to implement lazy-loading or pagination for the tree?
    • Will the tree be used in forms, tables, or both? Concurrent usage (e.g., filters + forms) may require caching or query optimization.
  3. User Experience:

    • Should the tree support multi-select (default for BelongsToMany) or single-select (default for BelongsTo)? Can this vary by context?
    • Are there accessibility requirements (e.g., keyboard navigation, screen reader support) beyond Filament’s defaults?
  4. Maintenance:

    • Who will own updates if Filament or Laravel introduces breaking changes? Is there a plan for forking or patching the package?
    • How will customizations (e.g., getTreeUsing) be documented and tested for future-proofing?
  5. Alternatives:

    • Could simpler solutions (e.g., nested select fields or a custom Vue component) meet requirements with less risk? Justify the trade-offs of this package’s complexity.

Integration Approach

Stack Fit

  • Primary Use Cases:
    • Forms: Replace static dropdowns for hierarchical selections (e.g., product categories, user roles).
    • Tables: Add filters or column-based tree selections (e.g., "Show only posts in category X").
    • Custom Components: Embed in Filament resources, pages, or widgets via SelectTree::make().
  • Compatibility:
    • Filament 4.x: Native support; follow the 4.x branch.
    • Filament 3.x: Use the 3.x branch (note: not the default 4.x tag).
    • Laravel 10/11: Confirmed compatibility; PHP 8.5+ required for latest features.
    • Frontend: Relies on treeselectjs (included via Filament’s asset pipeline). No additional build steps needed.

Migration Path

  1. Assessment Phase:

    • Audit existing hierarchical data models to identify relationships, query patterns, and edge cases (e.g., circular references, deep nesting).
    • Map use cases to package features (e.g., "Do we need enableBranchNode() for category filters?").
  2. Pilot Implementation:

    • Start with a non-critical form (e.g., a category selector for blog posts) to test:
      • Basic relationship integration (->relationship('categories', 'name', 'parent_id')).
      • Customization (e.g., ->withCount(), ->searchable()).
      • Performance with real data volumes.
    • Example minimal setup:
      use CodeWithDennis\FilamentSelectTree\SelectTree;
      
      SelectTree::make('categories')
          ->relationship('categories', 'name', 'parent_id')
          ->searchable()
          ->placeholder('Select a category...');
      
  3. Scaling to Tables/Filters:

    • Integrate into Filament tables using the Filter example from the README:
      Filter::make('category')
          ->form([
              SelectTree::make('categories')
                  ->relationship('categories', 'name', 'parent_id')
                  ->enableBranchNode(),
          ])
          ->query(fn(Builder $query, array $data) => $query->whereHas('categories', fn($q) => $q->whereIn('id', $data['categories'])));
      
    • Validate that indicateUsing() and query logic handle edge cases (e.g., empty selections).
  4. Advanced Customization:

    • For non-Eloquent hierarchies, use getTreeUsing() with closures or static arrays:
      SelectTree::make('custom_tree')
          ->getTreeUsing(fn() => $this->buildDynamicTree())
          ->treeKey('custom-tree');
      
    • Test prepend()/append() for static nodes (e.g., "All Categories" or "Uncategorized" options).

Compatibility

  • Database: Works with any Eloquent model supporting parent_id or custom parent keys. Test with:
    • Standard parent_id foreign keys.
    • Non-standard keys (e.g., parent_code) via ->withKey('code').
    • Soft-deleted models (->withTrashed()).
  • Caching: Leverage Filament’s caching or Laravel’s query caching for large hierarchies:
    ->modifyQueryUsing(fn($query) => $query->cachedFor(60))
    
  • Localization: Supports __() for placeholders/labels. Ensure translation keys align with your app’s locale files.

Sequencing

  1. Phase 1: Basic form integration (1–2 sprints).
  2. Phase 2: Table filters and validation (1 sprint).
  3. Phase 3: Custom tree logic (e.g., dynamic data, prepend/append) and performance tuning.
  4. Phase 4: Documentation and rollout to other teams.

Operational Impact

Maintenance

  • Dependencies:
    • Monitor treeselectjs and Filament for breaking changes. Subscribe to:
    • Update the package annually or when Filament/Laravel releases major versions.
  • Custom Code:
    • Centralize tree configurations (e.g., in a TreeField trait or helper class) to reduce duplication.
    • Document non-standard setups (e.g., getTreeUsing logic) in comments or a wiki.
  • Testing:
    • Add unit tests for custom tree logic (e.g., getTreeUsing closures).
    • Test edge cases:
      • Empty selections.
      • Circular references (if applicable).
      • Concurrent modifications (e.g., tree updates while a form is open).

Support

  • Troubleshooting:
    • Common issues:
      • Empty trees: Verify parent_id queries return data. Check strictNullParentRootNodes() if children are orphaned.
      • Performance: Use Laravel Debugbar to profile queries. Add indexes to
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity