Multi-Tenant SaaS: Queues, Notifications &amp; Storage | 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)    Multi-Tenant SaaS with Laravel + Filament: Scoped Queues, Notifications, and Storage per Tenant        On this page       1. [  The Problem With "Just Add a tenant\_id Column" ](#the-problem-with-quotjust-add-a-codetenant-idcode-columnquot)
2. [  1. Carrying Tenant Context Through Queued Jobs ](#1-carrying-tenant-context-through-queued-jobs)
3. [  Routing Jobs to Tenant-Specific Queues ](#routing-jobs-to-tenant-specific-queues)
4. [  2. Per-Tenant Notification Channels ](#2-per-tenant-notification-channels)
5. [  3. Isolated File Storage per Tenant ](#3-isolated-file-storage-per-tenant)
6. [  Wiring It Into Filament ](#wiring-it-into-filament)
7. [  Takeaways ](#takeaways)

  ![Multi-Tenant SaaS with Laravel + Filament: Scoped Queues, Notifications, and Storage per Tenant](https://cdn.msaied.com/387/d0e5a2093141363b7f5eeb68d1d7ef56.png)

  #laravel   #filament   #multi-tenancy   #saas   #queues  

 Multi-Tenant SaaS with Laravel + Filament: Scoped Queues, Notifications, and Storage per Tenant 
=================================================================================================

     7 Jul 2026      4 min read    ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said  

       Table of contents

1. [  01   The Problem With "Just Add a tenant\_id Column"  ](#the-problem-with-quotjust-add-a-codetenant-idcode-columnquot)
2. [  02   1. Carrying Tenant Context Through Queued Jobs  ](#1-carrying-tenant-context-through-queued-jobs)
3. [  03   Routing Jobs to Tenant-Specific Queues  ](#routing-jobs-to-tenant-specific-queues)
4. [  04   2. Per-Tenant Notification Channels  ](#2-per-tenant-notification-channels)
5. [  05   3. Isolated File Storage per Tenant  ](#3-isolated-file-storage-per-tenant)
6. [  06   Wiring It Into Filament  ](#wiring-it-into-filament)
7. [  07   Takeaways  ](#takeaways)

 The Problem With "Just Add a `tenant_id` Column"
------------------------------------------------

Most multi-tenancy tutorials stop at Eloquent global scopes. Real SaaS products have three additional isolation concerns that bite you in production:

1. **Queue jobs leaking tenant context** — a job dispatched for Tenant A runs without knowing which tenant it belongs to.
2. **Notifications hitting the wrong channel config** — Tenant B has a custom Slack webhook; Tenant A does not.
3. **File uploads colliding** — both tenants write `invoices/2024/report.pdf` to the same S3 bucket prefix.

Let's solve each one.

---

1. Carrying Tenant Context Through Queued Jobs
----------------------------------------------

The cleanest approach is a dedicated `TenantAware` interface combined with a `SerializesModels`-style middleware on the queue worker.

```php
// app/Contracts/TenantAware.php
interface TenantAware
{
    public function getTenantId(): int;
}

```

```php
// app/Jobs/Concerns/HasTenantContext.php
trait HasTenantContext
{
    public int $tenantId;

    public function getTenantId(): int
    {
        return $this->tenantId;
    }
}

```

```php
// app/Queue/Middleware/SetTenantContext.php
use App\Models\Tenant;
use App\Contracts\TenantAware;

class SetTenantContext
{
    public function handle(TenantAware $job, callable $next): void
    {
        $tenant = Tenant::findOrFail($job->getTenantId());
        app()->instance('current.tenant', $tenant);

        try {
            $next($job);
        } finally {
            app()->forgetInstance('current.tenant');
        }
    }
}

```

Any job that uses `HasTenantContext` and lists `SetTenantContext` in its `middleware()` method will have `app('current.tenant')` available throughout execution — including nested service calls.

### Routing Jobs to Tenant-Specific Queues

For high-value tenants on a paid tier you may want dedicated queue workers:

```php
public function queue(): string
{
    return match (true) {
        $this->tenant()->isPremium() => 'premium',
        default => 'default',
    };
}

```

Horizon picks this up automatically if you define a `premium` supervisor in `horizon.php`.

---

2. Per-Tenant Notification Channels
-----------------------------------

Laravel's notification system resolves channels at runtime, making it straightforward to swap configs:

```php
// app/Notifications/InvoicePaid.php
public function via(object $notifiable): array
{
    $tenant = app('current.tenant');

    return $tenant->slack_webhook_url
        ? ['mail', 'slack']
        : ['mail'];
}

public function toSlack(object $notifiable): SlackMessage
{
    $tenant = app('current.tenant');

    return (new SlackMessage)
        ->to($tenant->slack_webhook_url)
        ->text('Invoice paid: ' . $this->invoice->number);
}

```

For tenants that bring their own SMTP credentials, bind a contextual mailer inside a service:

```php
Mail::mailer(
    config()->set('mail.mailers.tenant_smtp', [
        'transport' => 'smtp',
        'host'      => $tenant->smtp_host,
        'username'  => $tenant->smtp_user,
        'password'  => decrypt($tenant->smtp_password),
    ]) ?? 'tenant_smtp'
);

```

Scope this setup to a request/job lifecycle so it never bleeds into other tenants.

---

3. Isolated File Storage per Tenant
-----------------------------------

Never let tenants share a flat S3 prefix. Use a dynamic disk resolved from the container:

```php
// app/Services/TenantDisk.php
use Illuminate\Support\Facades\Storage;

class TenantDisk
{
    public static function disk(): \Illuminate\Contracts\Filesystem\Filesystem
    {
        $tenant = app('current.tenant');

        $diskName = 'tenant_' . $tenant->id;

        if (! config()->has("filesystems.disks.{$diskName}")) {
            config([
                "filesystems.disks.{$diskName}" => [
                    'driver' => 's3',
                    'bucket' => config('filesystems.disks.s3.bucket'),
                    'root'   => "tenants/{$tenant->uuid}",
                    // inherit key/secret from default s3 config
                ] + config('filesystems.disks.s3'),
            ]);
        }

        return Storage::disk($diskName);
    }
}

```

Usage anywhere in the app:

```php
TenantDisk::disk()->put('invoices/report.pdf', $contents);

```

Each tenant's files live under `tenants/{uuid}/` — simple to audit, easy to delete on churn, and compatible with S3 bucket policies.

---

Wiring It Into Filament
-----------------------

Filament's panel provider exposes `tenant()` resolution. Register your context bootstrap there:

```php
public function boot(): void
{
    FilamentView::registerRenderHook(
        PanelsRenderHook::BODY_START,
        fn () => '' // side-effect: tenant already set by panel auth
    );
}

```

For file uploads inside Filament forms, swap the disk on the `FileUpload` field:

```php
FileUpload::make('attachment')
    ->disk(fn () => 'tenant_' . app('current.tenant')->id)
    ->directory('attachments')

```

---

Takeaways
---------

- Carry tenant context through jobs via a typed interface + queue middleware, not a global static.
- Resolve notification channels and mailer credentials at runtime from the bound tenant instance.
- Build per-tenant S3 disks lazily using `config()` mutation; prefix by UUID, not integer ID.
- Filament's `FileUpload` accepts a closure for `disk()`, making tenant-aware uploads a one-liner.
- Always `forgetInstance` in a `finally` block to prevent context leakage in long-lived Octane workers.

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fmulti-tenant-saas-with-laravel-filament-scoped-queues-notifications-and-storage-per-tenant&text=Multi-Tenant+SaaS+with+Laravel+%2B+Filament%3A+Scoped+Queues%2C+Notifications%2C+and+Storage+per+Tenant) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fmulti-tenant-saas-with-laravel-filament-scoped-queues-notifications-and-storage-per-tenant) 

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

  3 questions  

     Q01  Does mutating config() for per-tenant disks cause issues under Laravel Octane?        Yes, if you mutate the global config repository in an Octane worker it persists across requests. Wrap the mutation in a request-scoped singleton or use a dedicated Filesystem manager instance resolved fresh per request to avoid cross-tenant leakage. 

      Q02  How do I prevent a premium queue worker from accidentally processing default-queue jobs?        In horizon.php, set the premium supervisor's `queue` array to only `['premium']` and ensure its `balance` strategy is `false` or `simple`. This prevents Horizon from auto-balancing default jobs onto premium workers. 

      Q03  Can I use this pattern with Filament's built-in multi-tenancy (HasTenancy)?        Yes. Filament's HasTenancy trait handles panel-level query scoping. The queue middleware and storage patterns described here are complementary — they extend isolation to async jobs and file I/O that Filament's panel layer never touches. 

  Continue reading

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

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

 [ ![HTTP Query Method Support in Laravel 13.19](https://cdn.msaied.com/394/4c917aad559beddb5eeb9a7a1e107f4c.png) Laravel Laravel 13 HTTP Client 

### HTTP Query Method Support in Laravel 13.19

Laravel 13.19 adds Http::query() for the HTTP QUERY verb, query/queryJson testing helpers, a reduceInto() coll...

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

 8 Jul 2026     3 min read  

  Read    

 ](https://msaied.com/articles/http-query-method-support-in-laravel-1319) [ ![Blackfire & Xdebug Profiling in Laravel: Finding Real Bottlenecks in Production-Like Environments](https://cdn.msaied.com/393/a8dfc4ec52c4febc3ef41a491eb452ea.png) laravel performance profiling 

### Blackfire &amp; Xdebug Profiling in Laravel: Finding Real Bottlenecks in Production-Like Environments

Stop guessing where your Laravel app is slow. This guide walks through practical Blackfire and Xdebug profilin...

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

 8 Jul 2026     4 min read  

  Read    

 ](https://msaied.com/articles/blackfire-xdebug-profiling-in-laravel-finding-real-bottlenecks-in-production-like-environments) [ ![Laravel Cloud Security Defaults Behind Every Deploy](https://cdn.msaied.com/395/28df8f542fbe81ecee3ba4ad897f36d6.png) Laravel Cloud Security PHP 

### Laravel Cloud Security Defaults Behind Every Deploy

Laravel Cloud ships WAF rules, DDoS mitigation, automatic PHP patching, SOC 2 Type II compliance, and deploy-t...

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

 8 Jul 2026     4 min read  

  Read    

 ](https://msaied.com/articles/laravel-cloud-security-defaults-behind-every-deploy) 

   [  ![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)
