Filament Multi-Panel Auth &amp; Table Query Tuning | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com) [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles  ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

  [ home ](https://msaied.com)    [ articles ](https://msaied.com/articles)    Filament at Scale: Multi-Panel Auth, Custom Panels, and Table Query Tuning        On this page       1. [  Why Multi-Panel Filament Gets Messy Fast ](#why-multi-panel-filament-gets-messy-fast)
2. [  1. Separate Auth Guards Per Panel ](#1-separate-auth-guards-per-panel)
3. [  2. Scoping Resources to the Authenticated Tenant ](#2-scoping-resources-to-the-authenticated-tenant)
4. [  3. Table Query Tuning: The Three Common Killers ](#3-table-query-tuning-the-three-common-killers)
5. [  3a. Eager-load relationships used in columns ](#3a-eager-load-relationships-used-in-columns)
6. [  3b. Defer expensive columns ](#3b-defer-expensive-columns)
7. [  3c. Paginate aggressively and add database indexes ](#3c-paginate-aggressively-and-add-database-indexes)
8. [  Takeaways ](#takeaways)

  ![Filament at Scale: Multi-Panel Auth, Custom Panels, and Table Query Tuning](https://cdn.msaied.com/183/62be0d95101cf6a9babfd701562186ed.png)

  #filament   #laravel   #multi-tenant   #performance  

 Filament at Scale: Multi-Panel Auth, Custom Panels, and Table Query Tuning 
============================================================================

     15 Jun 2026      3 min read    ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said  

       Table of contents

1. [  01   Why Multi-Panel Filament Gets Messy Fast  ](#why-multi-panel-filament-gets-messy-fast)
2. [  02   1. Separate Auth Guards Per Panel  ](#1-separate-auth-guards-per-panel)
3. [  03   2. Scoping Resources to the Authenticated Tenant  ](#2-scoping-resources-to-the-authenticated-tenant)
4. [  04   3. Table Query Tuning: The Three Common Killers  ](#3-table-query-tuning-the-three-common-killers)
5. [  05   3a. Eager-load relationships used in columns  ](#3a-eager-load-relationships-used-in-columns)
6. [  06   3b. Defer expensive columns  ](#3b-defer-expensive-columns)
7. [  07   3c. Paginate aggressively and add database indexes  ](#3c-paginate-aggressively-and-add-database-indexes)
8. [  08   Takeaways  ](#takeaways)

 Why Multi-Panel Filament Gets Messy Fast
----------------------------------------

Filament's panel system is powerful, but teams often bolt on a second panel without thinking through auth isolation, query scope, or table performance. The result is shared session state, leaking queries, and N+1 problems hiding behind pretty UI. This article covers the three areas that matter most at scale.

---

1. Separate Auth Guards Per Panel
---------------------------------

Each panel should own its guard. Define them in `config/auth.php`:

```php
'guards' => [
    'admin' => [
        'driver'   => 'session',
        'provider' => 'admins',
    ],
    'tenant' => [
        'driver'   => 'session',
        'provider' => 'users',
    ],
],
'providers' => [
    'admins' => ['driver' => 'eloquent', 'model' => App\Models\Admin::class],
    'users'  => ['driver' => 'eloquent', 'model' => App\Models\User::class],
],

```

Then wire each panel to its guard inside the `PanelProvider`:

```php
// app/Providers/Filament/AdminPanelProvider.php
public function panel(Panel $panel): Panel
{
    return $panel
        ->id('admin')
        ->path('admin')
        ->authGuard('admin')
        ->login()
        ->middleware([
            EncryptCookies::class,
            StartSession::class,
            AuthenticateSession::class,
        ])
        ->authMiddleware([Authenticate::class]);
}

```

Critical: **do not share the default `web` middleware group** between panels unless you want session collisions. Each panel should declare its own middleware stack explicitly.

---

2. Scoping Resources to the Authenticated Tenant
------------------------------------------------

Global scopes are the cleanest way to ensure every Eloquent query inside a panel is automatically filtered. Register a scope in the panel's boot phase:

```php
// Inside TenantPanelProvider::panel()
->tenant(Team::class, ownershipRelationship: 'team')

```

For custom scoping beyond Filament's built-in tenancy, override `getEloquentQuery()` on the resource:

```php
public static function getEloquentQuery(): Builder
{
    return parent::getEloquentQuery()
        ->whereBelongsTo(filament()->getTenant());
}

```

Avoid putting this logic in a global Eloquent scope unless you also need it outside Filament — mixing panel concerns into your domain models is a maintenance trap.

---

3. Table Query Tuning: The Three Common Killers
-----------------------------------------------

### 3a. Eager-load relationships used in columns

```php
public static function table(Table $table): Table
{
    return $table
        ->query(
            Order::query()->with(['customer', 'items.product'])
        )
        ->columns([
            TextColumn::make('customer.name'),
            TextColumn::make('items_count')
                ->counts('items'),
        ]);
}

```

Filament's `->counts()` and `->exists()` column modifiers push aggregates into the base query rather than triggering per-row subqueries — use them instead of accessor methods.

### 3b. Defer expensive columns

For columns that require heavy joins or subqueries, mark them as toggleable and hidden by default:

```php
TextColumn::make('lifetime_value')
    ->toggleable(isToggledHiddenByDefault: true)
    ->getStateUsing(fn (Customer $r) => $r->orders()->sum('total')),

```

This keeps the default page load fast; power users can opt in.

### 3c. Paginate aggressively and add database indexes

Filament's default page size is 10, but teams often bump it to 50 or 100 without adding indexes on the sort column. Every `TextColumn::make('created_at')->sortable()` call becomes an `ORDER BY created_at` — ensure that column is indexed:

```php
$table->index(['team_id', 'created_at']);

```

A composite index on `(team_id, created_at)` satisfies both the tenant scope `WHERE` and the `ORDER BY` in a single index scan.

---

Takeaways
---------

- Assign a dedicated auth guard to every panel and declare middleware stacks explicitly to prevent session bleed.
- Scope resource queries at the resource level, not in global Eloquent scopes, to keep domain models clean.
- Use Filament's built-in `->counts()` and `->exists()` modifiers to push aggregates into SQL rather than PHP.
- Hide expensive columns behind `toggleable(isToggledHiddenByDefault: true)` to protect default page load times.
- Add composite indexes that match your tenant scope column plus the default sort column.

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fmsaied.com%2Farticles%2Ffilament-at-scale-multi-panel-auth-custom-panels-and-table-query-tuning&text=Filament+at+Scale%3A+Multi-Panel+Auth%2C+Custom+Panels%2C+and+Table+Query+Tuning) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmsaied.com%2Farticles%2Ffilament-at-scale-multi-panel-auth-custom-panels-and-table-query-tuning) 

 Frequently Asked Questions 
----------------------------

  3 questions  

     Q01  Can two Filament panels share the same Eloquent model for authentication?        Yes, but they should still use separate guards pointing to the same provider. This keeps session cookies and remember tokens isolated between panels, preventing one panel's logout from affecting the other. 

      Q02  Does Filament's built-in tenancy handle multi-panel setups automatically?        Filament's tenant() helper scopes one panel to a tenant model, but it does not coordinate across multiple panels. You need to configure tenancy independently on each PanelProvider and ensure middleware stacks do not overlap. 

      Q03  When should I override getEloquentQuery() versus using a global Eloquent scope?        Override getEloquentQuery() when the scope is specific to the Filament panel context. Reserve global Eloquent scopes for rules that must apply everywhere — API, CLI, and UI alike — to avoid unintended filtering outside the panel. 

  Continue reading

 More Articles 
---------------

 [ View all    ](https://msaied.com/articles) 

 [ ![PostgreSQL Window Functions in Laravel: Ranking, Running Totals, and Gap Detection](https://cdn.msaied.com/239/f588e7cbf8e6d3317a581ce0fa27140d.png) laravel postgresql eloquent 

### PostgreSQL Window Functions in Laravel: Ranking, Running Totals, and Gap Detection

Window functions let you compute rankings, running totals, and gaps directly in SQL without pulling rows into...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 19 Jun 2026     3 min read  

  Read    

 ](https://msaied.com/articles/postgresql-window-functions-in-laravel-ranking-running-totals-and-gap-detection) [ ![Custom Eloquent Casts: Encapsulating Domain Logic Inside Model Attributes](https://cdn.msaied.com/238/8e843e57a34f81f853eedefae629c09b.png) laravel eloquent domain-driven-design 

### Custom Eloquent Casts: Encapsulating Domain Logic Inside Model Attributes

Custom Eloquent casts let you push value-object logic directly into model attributes, keeping controllers and...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 19 Jun 2026     3 min read  

  Read    

 ](https://msaied.com/articles/custom-eloquent-casts-encapsulating-domain-logic-inside-model-attributes) [ !['The Story of PHP' Documentary Teaser Is Out — Watch It Now](https://cdn.msaied.com/237/78daf2c90e319b7a740ec4d48d5280c6.png) PHP Laravel Documentary 

### 'The Story of PHP' Documentary Teaser Is Out — Watch It Now

CultRepo has released a teaser for 'The Story of PHP', an upcoming documentary sponsored by JetBrains. It feat...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 18 Jun 2026     3 min read  

  Read    

 ](https://msaied.com/articles/the-story-of-php-documentary-teaser-is-out-watch-it-now) 

   [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

Explore

- [Home](https://msaied.com)
- [Projects](https://msaied.com/projects)
- [Articles](https://msaied.com/articles)
- [Certificates](https://msaied.com/certificates)
- [Contact](https://msaied.com#contact-section)

Connect

- [   hello@msaied.com ](mailto:hello@msaied.com)
- [   +20 109 461 9204 ](tel:+201094619204)

© 2026 Mohamed Said. All rights reserved.

 [  ](https://github.com/EG-Mohamed) [  ](https://www.linkedin.com/in/msaiedm/) [  ](https://wa.me/201094619204) [  ](mailto:hello@msaied.com) [  ](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
