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

Tables Laravel Package

filament/tables

Powerful table builder for Filament admin panels. Add searchable, sortable, filterable tables with actions, bulk actions, and column types. Integrates cleanly with Eloquent and supports pagination, customization, and responsive layouts.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require filament/tables
    

    Ensure filament/support and livewire/livewire are also installed (core dependencies).

  2. Basic Usage Add the HasTable trait to a Livewire component:

    use Filament\Tables\Contracts\HasTable;
    use Filament\Tables\Table;
    
    class UserTable extends Table implements HasTable
    {
        protected static ?string $model = User::class;
    
        public function table(Table $table): Table
        {
            return $table
                ->columns([
                    TextColumn::make('name'),
                    TextColumn::make('email'),
                ])
                ->filters([
                    // Add filters here
                ]);
        }
    }
    
  3. First Render Use the table in a Livewire component:

    use Filament\Tables\Table;
    
    class UsersPage extends Component
    {
        public function table(Table $table): Table
        {
            return $table->resource(UserTable::class);
        }
    }
    
  4. Key Files to Explore

    • config/filament.php (global table settings)
    • app/Providers/FilamentServiceProvider.php (publish config/views if needed)
    • resources/views/filament/tables/ (customize default views)

Implementation Patterns

Core Workflows

  1. Column Definitions

    • Use column classes (TextColumn, BooleanColumn, SelectColumn, etc.) for type-specific rendering.
    • Example:
      TextColumn::make('status')
          ->badge()
          ->color(fn (string $state): string => match ($state) {
              'active' => 'success',
              'inactive' => 'danger',
          })
      
  2. Actions & Bulk Actions

    • Define row-level actions:
      Table::make()
          ->actions([
              Action::make('edit')
                  ->icon('heroicon-o-pencil')
                  ->url(fn ($record) => route('users.edit', $record)),
          ])
      
    • Bulk actions (with confirmation):
      ->bulkActions([
          Tables\Actions\BulkAction::make('delete')
              ->requiresConfirmation()
              ->action(fn (Collection $records) => User::whereKey($records->pluck('id'))->delete()),
      ])
      
  3. Filters & Search

    • Add filters dynamically:
      ->filters([
          SelectFilter::make('status')
              ->options(['active', 'inactive'])
              ->label('User Status'),
          DateRangeFilter::make('created_at')
              ->label('Created Date'),
      ])
      
    • Global search:
      ->searchable(['name', 'email'])
      
  4. Pagination & Sorting

    • Customize via Table methods:
      ->paginate(10)
      ->defaultSort('name', 'asc')
      
  5. Relationships

    • Use RelationshipManager or nested tables:
      BelongsToManyColumn::make('roles')
          ->relationship('roles', 'name')
          ->searchable()
      

Integration Tips

  • Laravel Scout: Enable full-text search:
    ->searchable(['scout'])
    
  • Livewire Hooks: Extend table behavior:
    protected function getTable(): Table
    {
        $table = parent::getTable();
        $table->hook('rendered', fn () => $this->dispatch('table-rendered'));
        return $table;
    }
    
  • Custom Views: Override default Blade templates in resources/views/filament/tables/.

Gotchas and Tips

Common Pitfalls

  1. Model Binding Issues

    • Ensure $model is set statically (e.g., protected static ?string $model = User::class).
    • For polymorphic tables, use ->query(fn (Builder $query) => $query->where('type', $this->type)).
  2. Column Visibility

    • Hidden columns still consume query time. Use ->hidden() sparingly:
      TextColumn::make('secret_key')->hidden()
      
  3. Filter Performance

    • Avoid complex filters in ->query() that aren’t optimized (e.g., LIKE on large text fields).
    • Use ->default() to pre-set filter values:
      SelectFilter::make('status')->default('active')
      
  4. Livewire State Bloat

    • Large datasets can bloat Livewire’s state. Use ->paginate(20) or ->lazy() for big tables.
  5. CSRF Token Conflicts

    • If using bulk actions with custom routes, ensure CSRF tokens are included in the request.

Debugging Tips

  • Log Queries: Enable Laravel’s query logging:
    \DB::enableQueryLog();
    $this->table->getQuery()->toSql(); // Inspect the final query
    
  • Table Rendering: Check if hooks/filters are firing:
    $table->hook('building', fn () => \Log::debug('Table building...'));
    
  • Asset Conflicts: Clear cached views:
    php artisan view:clear
    php artisan filament:cache-reset
    

Extension Points

  1. Custom Columns Create a new column class by extending Filament\Tables\Columns\Column:

    class CustomColumn extends Column
    {
        protected string $view = 'filament.tables.columns.custom';
    }
    
  2. Table Modifiers Use TableModifier to alter table behavior:

    $table->modify(fn (Table $table) => $table->disableActions());
    
  3. Plugin System Register plugins in FilamentServiceProvider:

    Filament::registerTablePlugin(
        TablePlugin::make()
            ->modifyTableQueryUsing(fn (Builder $query) => $query->where('is_active', true))
    );
    
  4. Localization Override translations in config/filament.php or publish views:

    php artisan vendor:publish --tag=filament-tables-views
    
  5. Testing Use Filament\Tables\Tests\Concerns\InteractsWithTables for unit tests:

    use Filament\Tables\Tests\Concerns\InteractsWithTables;
    
    class UserTableTest extends TestCase
    {
        use InteractsWithTables;
    
        public function test_table_columns()
        {
            $this->assertTableColumn('name', UserTable::class);
        }
    }
    
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport