Multi-Tenant SaaS: Queues, Notifications &amp; Storage | 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. Multi-Tenant SaaS with Laravel + Filament: Scoped Queues, Notifications, and Storage per Tenant

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

 Beyond basic query scoping, production multi-tenant SaaS demands isolated queues, per-tenant notification channels, and segregated file storage. This guide tackles all three with concrete Laravel + Filament patterns.

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

ShareCopy linkCopied

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

  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)

 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.

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

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

  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.

   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.

   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.

   ![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 articleProduction AI Agents in Laravel: Streaming, Token Budgets, and Structured Output Contracts](https://www.msaied.com/public/articles/production-ai-agents-in-laravel-streaming-token-budgets-and-structured-output-contracts-2) [Next articleClean Architecture Testing with Pest: Actions, Fakes, and Architectural Assertions](https://www.msaied.com/public/articles/clean-architecture-testing-with-pest-actions-fakes-and-architectural-assertions)  

   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)

 ###  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)
