PHPackages                             kisame76/filament-db-table-state - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. kisame76/filament-db-table-state

ActiveLibrary[Database &amp; ORM](/categories/database)

kisame76/filament-db-table-state
================================

Persist Filament table state (filters, sort, search, column order &amp; visibility) per user in the database, across devices and sessions.

v1.0.0(today)01↑2900%MITPHPPHP ^8.2CI passing

Since Jun 9Pushed todayCompare

[ Source](https://github.com/Kisame76/filament-db-table-state)[ Packagist](https://packagist.org/packages/kisame76/filament-db-table-state)[ Docs](https://github.com/Kisame76/filament-db-table-state)[ RSS](/packages/kisame76-filament-db-table-state/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

[ ![Filament DB Table State](https://repository-images.githubusercontent.com/1263977432/2540bf07-5b4a-4a93-b3ee-d46745564623)](https://github.com/Kisame76/filament-db-table-state)Filament DB Table State
=======================

[](#filament-db-table-state)

[![Filament](https://camo.githubusercontent.com/38cc5644d3daa49e293f5e9b28c4678fd2951f9e1eaf93427df4c4c55f97765b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46696c616d656e742d342e78253230253743253230352e782d4664414534423f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://filamentphp.com)[![Latest Version on Packagist](https://camo.githubusercontent.com/b6e2d6b267af6fb570b25abecc8a3c7bb77b65e9f1a92720e92b8b127f0fa1b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6973616d6537362f66696c616d656e742d64622d7461626c652d73746174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kisame76/filament-db-table-state)[![Tests](https://camo.githubusercontent.com/17a95f78d64c8706a53b9a95aae46fc3cf2986d85c639c5b08531903c5d304ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4b6973616d6537362f66696c616d656e742d64622d7461626c652d73746174652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/Kisame76/filament-db-table-state/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/f4c86972764c39e61bcb521feb6ed93faa833afe4d2d7b11a5828e8e24a91f9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6973616d6537362f66696c616d656e742d64622d7461626c652d73746174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kisame76/filament-db-table-state)

Persist Filament table state — **filters, sort, search, column order and column visibility** — per user in the **database**, instead of only the session.

Filament can already persist table state with `->persistFiltersInSession()`, `->persistSortInSession()`, `->persistColumnsInSession()` and friends. But the session is per-browser and short-lived: clear cookies, switch device or let the session expire and the state is gone.

This package mirrors that same state into a database row keyed by the user, so a user's filters and column layout **survive new sessions and follow them across devices**. By default it upgrades every table you already flag with `->persist*InSession()`; flip one switch to cover every table.

How it works
------------

[](#how-it-works)

Filament writes table state to the session (when the `->persist*InSession()` flags are on). This package hooks into Livewire globally and:

1. **Seeds** the session from the user's saved DB row on component boot — *before* Filament's `bootedInteractsWithTable()` reads it.
2. **Snapshots** the session back to the DB at the end of the request — *after* Filament has written the latest state.

It reuses Filament's own session keys (`getTableFiltersSessionKey()`, `getTableSortSessionKey()`, `getTableColumnsSessionKey()`, …), so it stays compatible with how Filament stores state. Each table gets its own small row per user, holding just that table's state.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Filament v4 or v5
- Livewire v3.5+ / v4

Installation
------------

[](#installation)

```
composer require kisame76/filament-db-table-state
```

Publish and run the migration (creates the `table_states` table):

```
php artisan vendor:publish --tag=filament-db-table-state-migrations
php artisan migrate
```

The migration adds a `user_id` foreign key with a cascade delete to your `users`table. Using UUID/ULID keys or a custom users table? Edit the published migration before running `migrate` — it has inline comments showing what to change.

That's it. Any table that uses Filament's session persistence (`->persistFiltersInSession()`, `->persistSortInSession()`, `->persistColumnsInSession()`, …) now also persists to the **database** — surviving new sessions and following the user across devices. To enable it for *every* table automatically, set `auto_enable_persistence => true` (see below).

Configuration (optional)
------------------------

[](#configuration-optional)

```
php artisan vendor:publish --tag=filament-db-table-state-config
```

```
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,
];
```

### Custom user resolution

[](#custom-user-resolution)

Need a custom guard or extra scoping? Set a resolver from any service provider's `boot()`:

```
use Kisame76\FilamentDbTableState\Support\TableStatePersister;

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

### What persists, and when

[](#what-persists-and-when)

The package mirrors whatever Filament writes to the **session** — it never touches the URL:

- **Column layout** (visibility + order): Filament persists this to the session *by default*, so it is **always** mirrored to the database, on every table, while the package is enabled.
- **Filters, sort, search**: Filament keeps these in the **URL query string** by default (not the session), so they are mirrored only once you opt the table in (or enable every table — see below).

### Default: opt in for filters, sort &amp; search

[](#default-opt-in-for-filters-sort--search)

Out of the box (`auto_enable_persistence => false`), turn on Filament's native session persistence for the tables you care about:

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

Those tables now persist filters and sort to the database as well — surviving new sessions and following the user across devices.

### Filament's session-persistence methods

[](#filaments-session-persistence-methods)

These are the native Filament `Table` methods this package mirrors to the database. The defaults are Filament's own — note that only the column layout is persisted out of the box:

MethodPersistsDefault`->persistFiltersInSession()`Filtersoff`->persistSortInSession()`Sortoff`->persistSearchInSession()`Table searchoff`->persistColumnSearchesInSession()`Per-column searchesoff`->persistColumnsInSession()`Column visibility + order**on**Enable all of them on a single table:

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

Every method also accepts `false` to turn it off — handy when `auto_enable_persistence` is on and you want to exclude one table, e.g. `->persistColumnsInSession(false)`.

### Persist every table automatically

[](#persist-every-table-automatically)

Set `auto_enable_persistence => true` to flip Filament's session persistence on for **every** table via `Table::configureUsing()` — no per-table changes needed.

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

When this is on, opt a single table back out by chaining the native flags in its `table()` method — your call wins:

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

### Custom global combinations

[](#custom-global-combinations)

`auto_enable_persistence => true` is a shortcut that turns *everything* on for every table. For any other global combination — say, persist filters on every table but never persist columns — leave `auto_enable_persistence => false` and configure Filament yourself in your app's `AppServiceProvider::boot()`:

```
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
    });
}
```

The package's hook mirrors whatever ends up in the session, so that is all you need: filters now persist to the database everywhere, columns nowhere. Keep `auto_enable_persistence => false` so the package doesn't flip its own defaults on top of yours.

### Turning it off

[](#turning-it-off)

Set `enabled => false` to switch the whole package off — no hook, no mirroring.

Notes &amp; caveats
-------------------

[](#notes--caveats)

- Each table has its own small row per user (keyed by user and table), so reads and writes only ever touch that one table's state.
- Persistence is **fail-safe**: any error while reading/writing state is swallowed so it can never break a page.
- Two browser tabs editing the same table can race on the last write; the most recent request wins.

License
-------

[](#license)

MIT — see [LICENSE.md](LICENSE.md).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ddd202513600df9ae7842cac3187f2877b5b5a977ea64578ee9e2fdaa3ca7c7?d=identicon)[Kisame76](/maintainers/Kisame76)

---

Top Contributors

[![Kisame76](https://avatars.githubusercontent.com/u/150232897?v=4)](https://github.com/Kisame76 "Kisame76 (2 commits)")

---

Tags

laravelpersistencelivewirefilterstablesfilament

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/kisame76-filament-db-table-state/health.svg)

```
[![Health](https://phpackages.com/badges/kisame76-filament-db-table-state/health.svg)](https://phpackages.com/packages/kisame76-filament-db-table-state)
```

###  Alternatives

[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[stephenjude/filament-jetstream

A Laravel starter kit built with Filament inspired by Jetstream.

17758.9k2](/packages/stephenjude-filament-jetstream)[stephenjude/filament-debugger

About

103150.5k2](/packages/stephenjude-filament-debugger)[mradder/filament-logger

Audit logging, activity tracking, exports, alerts, and dashboards for Filament admin panels.

2210.5k](/packages/mradder-filament-logger)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17555.1k](/packages/lacodix-laravel-model-filter)[andreia/filament-ui-switcher

Add a modal with options to switch between different UI layouts and styles (colors, fonts, font sizes).

245.8k](/packages/andreia-filament-ui-switcher)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
