ArtisanTinkerer.github.io

Blog

View on GitHub

Multi-Tenant Laravel - Tom Schlick

Laracon US 2017

Why?

DB Structure

Strategy: Single Database

class TenantScope implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        $builder->where('tenant_id',tenant()->id);
    }
}

And apply to models:

protected static function boot()
{
    parent::boot();

    static::addGlobalScope(new TenantScope);
}

Pros

Strategy Multiple Databases

How

Pro

Don

Choosing Strategy

  1. Do you commonly need to display information from multiple tenants on the same page?
  2. Do you need the option to segment, export, or privately host data for particular customers?
  3. Do you plan to use a lot of third party packages?
  4. Is your customer’s data highly sensitive?

Segment all things

Queued Jobs