Filament Multi-Panel Auth &amp; Table Query Tuning | Mohamed Said       [Skip to content](#main)  [ ![](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png) Mohamed SaidLaravel Backend Engineer ](https://www.msaied.com/public) - [Home](https://www.msaied.com/public)
- [Projects](https://www.msaied.com/public/projects)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [About](https://www.msaied.com/public#about)

           [  Contact](https://www.msaied.com/public#contact) Menu 

Menu
----

Close 

 - [HomeStart here](https://www.msaied.com/public)
- [ProjectsCase studies](https://www.msaied.com/public/projects)
- [ArticlesEngineering notes](https://www.msaied.com/public/articles)
- [CertificatesCredentials](https://www.msaied.com/public/certificates)
- [AboutHow I work](https://www.msaied.com/public#about)
- [ContactGet in touch](https://www.msaied.com/public#contact)

  [Start a conversation](https://www.msaied.com/public#contact) [WhatsApp](https://wa.me/201094619204) [Email](mailto:hello@msaied.com) 

 1. [Home](https://www.msaied.com/public)
2. /
3. [Articles](https://www.msaied.com/public/articles)
4. /
5. Filament at Scale: Multi-Panel Auth, Custom Panels, and Table Query Tuning

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

 Running Filament across multiple panels with separate auth guards and tuning table queries for large datasets requires deliberate architecture. Here is how to do it without hacks.

 ![](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp) [Mohamed Said](https://www.msaied.com/public#person) Published 22 Jul 2026 · Updated 22 Jul 2026 · 3 min read

ShareCopy linkCopied

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

  On this page +1. [Filament at Scale: Multi-Panel Auth, Custom Panels, and Table Query Tuning](#filament-at-scale-multi-panel-auth-custom-panels-and-table-query-tuning)
2. [Registering Multiple Panels](#registering-multiple-panels)
3. [Isolating Auth Guards](#isolating-auth-guards)
4. [Custom Panel Middleware for Tenant Resolution](#custom-panel-middleware-for-tenant-resolution)
5. [Table Query Tuning at Scale](#table-query-tuning-at-scale)
6. [Disable the Count Query When Unnecessary](#disable-the-count-query-when-unnecessary)
7. [Eager-Load Relationship Columns](#eager-load-relationship-columns)
8. [Key Takeaways](#key-takeaways)

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

Filament v3/v4 ships with a clean panel-per-provider model, but most tutorials stop at a single `AdminPanelProvider`. Production SaaS apps routinely need an **admin panel**, a **tenant panel**, and a **public-facing portal** — each with its own auth guard, middleware stack, and URL prefix. Add a table that pages through 500 k rows and you have a real engineering problem.

This article covers both concerns with concrete, copy-paste-ready patterns.

---

Registering Multiple Panels
---------------------------

Each panel lives in its own service provider. Register them all in `bootstrap/providers.php`.

```php
// app/Providers/Filament/AdminPanelProvider.php
public function panel(Panel $panel): Panel
{
    return $panel
        ->id('admin')
        ->path('admin')
        ->authGuard('admin')          // dedicated guard
        ->login(AdminLogin::class)
        ->middleware([
            EncryptCookies::class,
            VerifyCsrfToken::class,
            RequireAdminRole::class,  // custom middleware
        ])
        ->resources([
            UserResource::class,
            TenantResource::class,
        ]);
}

```

```php
// app/Providers/Filament/TenantPanelProvider.php
public function panel(Panel $panel): Panel
{
    return $panel
        ->id('tenant')
        ->path('app')
        ->authGuard('web')            // standard guard, tenant resolved by middleware
        ->tenant(Team::class, slugAttribute: 'slug')
        ->tenantMiddleware([EnsureTeamIsActive::class], isPersistent: true)
        ->resources([DashboardResource::class]);
}

```

### Isolating Auth Guards

Define a dedicated `admin` guard in `config/auth.php`:

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

```

This means an authenticated `User` session cannot bleed into the admin panel — a common security gap when teams share a single guard.

---

Custom Panel Middleware for Tenant Resolution
---------------------------------------------

When the tenant panel resolves a team from the URL slug, you want that team bound into the container early so every resource query can scope itself automatically.

```php
class ResolveCurrentTeam
{
    public function handle(Request $request, Closure $next): mixed
    {
        $team = Team::where('slug', $request->route('tenant'))->firstOrFail();

        app()->instance(CurrentTeam::class, $team);
        app()->instance('current_team_id', $team->id);

        return $next($request);
    }
}

```

Resources then inject `CurrentTeam` via the container rather than re-querying:

```php
public static function getEloquentQuery(): Builder
{
    return parent::getEloquentQuery()
        ->where('team_id', app('current_team_id'));
}

```

---

Table Query Tuning at Scale
---------------------------

Filament tables issue a `COUNT(*)` for pagination and a `SELECT` for the page. On large tables both queries hit the same indexes — or miss them.

### Disable the Count Query When Unnecessary

```php
public function table(Table $table): Table
{
    return $table
        ->paginated([25, 50, 100])
        ->paginationPageOptions([25, 50])
        ->extremePaginationLinks(false)
        ->query(
            Invoice::query()
                ->select(['id','number','status','total','created_at'])
                ->with('customer:id,name')   // avoid N+1
        );
}

```

For very large tables, replace the default paginator with a **cursor paginator** — Filament supports it natively:

```php
->paginationMode(PaginationMode::Cursor)

```

Cursor pagination skips `COUNT(*)` entirely and uses a keyset on an indexed column.

### Eager-Load Relationship Columns

Every `TextColumn` that calls `->relationship()` under the hood issues a separate query per row unless you declare the relationship in `$with` or override `getEloquentQuery()`.

```php
TextColumn::make('customer.name')
    ->searchable(query: function (Builder $query, string $search): Builder {
        return $query->whereHas('customer', fn ($q) =>
            $q->where('name', 'like', "%{$search}%")
        );
    }),

```

Always profile with `\DB::enableQueryLog()` or Telescope before deploying a new resource to production.

---

Key Takeaways
-------------

- Register each panel in its own provider; use `->authGuard()` to isolate session state per audience.
- Bind resolved tenant models into the container in persistent middleware so resources never re-query.
- Use `->select()` on the base query to avoid fetching unused columns across wide tables.
- Switch to cursor pagination for append-only or time-series tables to eliminate expensive `COUNT(*)` calls.
- Always declare eager-loads explicitly; Filament's relationship columns will not batch-load automatically unless you tell them to.

- [filament](https://www.msaied.com/public/articles?search=filament)
- [laravel](https://www.msaied.com/public/articles?search=laravel)
- [performance](https://www.msaied.com/public/articles?search=performance)
- [multi-tenant](https://www.msaied.com/public/articles?search=multi-tenant)

 Frequently asked questions 
---------------------------

  Can two Filament panels share the same Eloquent model but use different guards?Yes. The guard controls which session store and provider are used for authentication, not which model is queried. You can point both guards at the same `User` model but use different providers or add role checks in panel middleware.

   Does cursor pagination work with Filament's search and filter features?Cursor pagination works with filters that do not change the sort order. Full-text search that re-orders results by relevance is incompatible with keyset cursors; fall back to offset pagination for those cases.

   How do I prevent a logged-in admin from accessing the tenant panel URL directly?Add a custom middleware to the tenant panel's `-&gt;middleware()` stack that checks `auth()-&gt;guard('web')-&gt;check()` and redirects admins away. Because each panel uses a separate guard, the admin session is invisible to the tenant panel by default, but an admin who also has a web session could still access it without the extra check.

   ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)About the author
----------------

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

[About](https://www.msaied.com/public#about) [GitHub ↗](https://github.com/EG-Mohamed) [LinkedIn ↗](https://www.linkedin.com/in/msaiedm/) [WhatsApp ↗](https://wa.me/201094619204) [Email Address ↗](mailto:hello@msaied.com) [My CV ↗](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)  

   [Previous articleBuilding a Laravel Package: Service Providers, Auto-Discovery, and Config Merging](https://www.msaied.com/public/articles/building-a-laravel-package-service-providers-auto-discovery-and-config-merging-2) [Next articleFilament v4.12.2 Released: Bug Fixes for Toggle, Builder, Repeater, and More](https://www.msaied.com/public/articles/filament-v4122-released-bug-fixes-for-toggle-builder-repeater-and-more)  

   On this page
-------------

1. [Filament at Scale: Multi-Panel Auth, Custom Panels, and Table Query Tuning](#filament-at-scale-multi-panel-auth-custom-panels-and-table-query-tuning)
2. [Registering Multiple Panels](#registering-multiple-panels)
3. [Isolating Auth Guards](#isolating-auth-guards)
4. [Custom Panel Middleware for Tenant Resolution](#custom-panel-middleware-for-tenant-resolution)
5. [Table Query Tuning at Scale](#table-query-tuning-at-scale)
6. [Disable the Count Query When Unnecessary](#disable-the-count-query-when-unnecessary)
7. [Eager-Load Relationship Columns](#eager-load-relationship-columns)
8. [Key Takeaways](#key-takeaways)

 ###  Have a technical challenge?

 Tell me what you’re building. I reply within two working days.

[Start a conversation](https://www.msaied.com/public#contact) 

   Related articles
-----------------

 [ ![](https://cdn.msaied.com/740/cce86edc21eddcbdd2f2454fadaf9c70.png)  · 3 min read### The Pipeline Pattern in Laravel: Custom Pipelines Beyond Middleware

5 Oct 2026 ](https://www.msaied.com/public/articles/the-pipeline-pattern-in-laravel-custom-pipelines-beyond-middleware-1) [ ![](https://cdn.msaied.com/739/2d6897fdcdcf090613f96f72a64b8a78.png)  · 4 min read### MySQL Full-Text Search in Laravel: Indexes, Relevance Scoring, and Boolean Mode

4 Oct 2026 ](https://www.msaied.com/public/articles/mysql-full-text-search-in-laravel-indexes-relevance-scoring-and-boolean-mode) [ ![](https://cdn.msaied.com/738/073696a3fefe18bec825beec5ac658f5.png)  · 4 min read### Laravel Queue Rate-Limited Middleware: Throttling Jobs Without Losing Work

4 Oct 2026 ](https://www.msaied.com/public/articles/laravel-queue-rate-limited-middleware-throttling-jobs-without-losing-work) 

  Have a technical challenge?
----------------------------

Tell me what you’re building. I reply within two working days.

 [Discuss your project ↗](https://www.msaied.com/public#contact) 

  © 2026 Mohamed Said · Built with Laravel, meant to last.Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

 - [Home](https://www.msaied.com/public)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [GitHub](https://github.com/EG-Mohamed)
- [LinkedIn](https://www.linkedin.com/in/msaiedm/)
- [WhatsApp](https://wa.me/201094619204)
- [Email Address](mailto:hello@msaied.com)
- [My CV](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
- [Sitemap](https://www.msaied.com/public/sitemap.xml)
