PHP code example of kisame76 / filament-db-table-state

1. Go to this page and download the library: Download kisame76/filament-db-table-state library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kisame76 / filament-db-table-state example snippets


return [
    // Master switch. When false the package does nothing.
    'enabled' => env('DB_TABLE_STATE_ENABLED', true),

    // Default false = only tables you've flagged with ->persist*InSession()
    // are mirrored. Set true to flip those flags on for EVERY table.
    'auto_enable_persistence' => false,

    // Storage. user_column is a string so it supports integer and UUID keys.
    'table' => 'table_states',
    'user_column' => 'user_id',

    // Auth guard used to resolve the current user (null = default guard).
    'guard' => null,
];

use Kisame76\FilamentDbTableState\Support\TableStatePersister;

TableStatePersister::resolveUserIdUsing(fn () => auth('admin')->id());

public function table(Table $table): Table
{
    return $table
        ->persistFiltersInSession()
        ->persistSortInSession();
    // column layout already persists by default
}

public function table(Table $table): Table
{
    return $table
        ->persistFiltersInSession()
        ->persistSortInSession()
        ->persistSearchInSession()
        ->persistColumnSearchesInSession()
        ->persistColumnsInSession();
}

// config/db-table-state.php
'auto_enable_persistence' => true,

public function table(Table $table): Table
{
    return $table
        ->persistFiltersInSession(false)
        ->persistColumnsInSession(false);
}

use Filament\Tables\Table;

public function boot(): void
{
    Table::configureUsing(function (Table $table): void {
        $table
            ->persistFiltersInSession()       // filters on every table → mirrored to the DB
            ->persistColumnsInSession(false); // never persist the column layout
    });
}
bash
php artisan vendor:publish --tag=filament-db-table-state-migrations
php artisan migrate
sql
  DELETE FROM table_states WHERE table_key = 'App\Filament\Resources\Users\Pages\ListUsers';