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 Table Select Laravel Package

dvarilek/filament-table-select

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require dvarilek/filament-table-select:^2.0.7
    

    Publish the config (optional):

    php artisan vendor:publish --provider="Dvarilek\FilamentTableSelect\FilamentTableSelectServiceProvider"
    
  2. First Use Case: Replace a standard Select field in a Filament form with TableSelect for a related model. Example in a resource's Form class:

    use Dvarilek\FilamentTableSelect\Forms\Components\TableSelect;
    
    TableSelect::make('user_id')
        ->relationship('users') // BelongsTo relationship
        ->column('name') // Display column
        ->searchable()
        ->required(),
    
  3. Where to Look First:

    • Package README for basic usage.
    • config/filament-table-select.php for global defaults (e.g., table styling, search behavior).
    • src/Forms/Components/TableSelect.php for method reference and customization hooks.

Implementation Patterns

Core Workflows

  1. Basic Relationship Handling:

    • Use ->relationship('posts') for hasMany/belongsTo relationships.
    • For polymorphic relations, use ->polymorphic() and specify the relatedKey/foreignKey.
  2. Table Customization:

    • Override table columns dynamically:
      TableSelect::make('author_id')
          ->relationship('authors')
          ->tableColumns([
              Tables\Columns\TextColumn::make('name'),
              Tables\Columns\IconColumn::make('verified')->boolean(),
          ]),
      
    • Reuse existing table classes:
      ->tableUsing(AuthorTable::class),
      
  3. Search and Filtering:

    • Enable global search:
      ->searchable()
      ->searchDebounce(300),
      
    • Add custom filters:
      ->tableFilters([
          'is_active' => fn (Tables\Filters\Filter $filter) => $filter->toggle(),
      ]),
      
  4. Multi-Select:

    TableSelect::make('tags')
        ->relationship('tags')
        ->multiple()
        ->preload(),
    
  5. Integration with Existing Forms:

    • Works seamlessly with Filament’s Form and Table components.
    • Supports all standard Filament form methods (e.g., ->required(), ->rules()).

Advanced Patterns

  1. Dynamic Relationships:

    ->relationship(fn () => $this->getDynamicRelation())
    

    Useful for conditional logic (e.g., tenant-specific relations).

  2. Custom Table Actions: Add actions to the select table:

    ->tableActions([
        Tables\Actions\EditAction::make(),
    ]),
    
  3. Lazy Loading: Use ->preload() to eager-load relationships and reduce N+1 queries.

  4. Conditional Rendering:

    ->visible(fn ($record) => $record->canSelectAuthors())
    

Gotchas and Tips

Common Pitfalls

  1. Performance:

    • Issue: Slow rendering with large datasets.
    • Fix: Use ->searchable() + ->searchDebounce() and paginate the table:
      ->tablePagination(10),
      
    • Tip: Preload relationships in the parent model’s with() method.
  2. Relationship Mismatches:

    • Issue: Undefined relationship errors if the relationship name doesn’t match.
    • Fix: Verify the relationship exists in the model and use the exact name (e.g., ->relationship('posts') for $this->posts()).
  3. Caching:

    • Issue: Table data not updating after changes.
    • Fix: Clear Filament’s cache:
      php artisan filament:cache-reset
      
  4. Polymorphic Relations:

    • Issue: Incorrect model binding in polymorphic cases.
    • Fix: Explicitly set relatedKey and foreignKey:
      ->polymorphic()
      ->relatedKey('authorable_id')
      ->foreignKey('authorable_type'),
      

Debugging Tips

  1. Log Table Queries: Enable Laravel’s query logging to debug slow tables:

    ->tableUsing(fn () => {
        $table = AuthorTable::make();
        $table->queryLog = true; // Custom property to inspect queries
        return $table;
    }),
    
  2. Check Config Overrides: Ensure no global config in config/filament-table-select.php conflicts with your component settings.

  3. Inspect Rendered HTML: Use browser dev tools to verify the table structure and identify missing CSS/JS.

Extension Points

  1. Custom Table Classes: Extend Filament\Tables\Table to add reusable logic:

    class CustomAuthorTable extends Table {
        public function getTableSelectQuery(): Builder {
            return parent::getTableSelectQuery()->where('is_active', true);
        }
    }
    
  2. Event Hooks: Listen for filament-table-select.rendered events to modify the table after initialization.

  3. Blade Overrides: Override the default table view in resources/views/vendor/filament-table-select/table.blade.php.

  4. Localization: Extend the package’s language lines in resources/lang/en/filament-table-select.php.

Pro Tips

  • Use ->tableUsing() for Complex Tables: For tables with custom actions, bulk actions, or complex filters, define a dedicated table class.
  • Combine with Filament Actions: Add ->tableActions() to enable inline editing/deletion of selected records.
  • Leverage Filament’s Built-in Features: Use ->tableColumns() to include Filament’s rich columns (e.g., BadgeColumn, ToggleColumn).
  • Test Edge Cases: Test with empty relationships, disabled states, and large datasets early in development.
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours