Subdomain Multitenency Package for Laravel

Subdomain Multitenency Package for Laravel

Romega Digital released a package to make it easier to create subdomain-based multitenancy in your Laravel applications:

This package is meant to be a quick and easy way to add multitenancy to your Laravel application. It simply creates models and relationships for Tenants and models. The package identifies incoming traffic by subdomain, and finds a corresponding tenant in the Tenant table. If none are found or the user is not associated with a particular subdomain, the user is met with a 403 error.

Remega’s package provides multitenant support to your models through a trait called HasTenants, and also leverages Spatie’s permissions package for some functionality.

Related: Two Best Laravel Packages to Manage Roles/Permissions

Here’s an example from the readme:

use Spatie\Permission\Traits\HasRoles;
use RomegaDigital\Multitenancy\Traits\HasTenants;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
    use HasTenants, HasRoles;

    // ...

With the HasTenants trait in place, you can get the users associated with a Tenant model:


And finally here’s how you create tenants:

        'name'    => 'An Identifying Name',
        'domain'  => 'tenant1'
        'name'    => 'A Second Customer',
        'domain'  => 'tenant2'

Along with this package, there’s an accompanying Nova package called Multitenency Nova Tool to manage the multitenancy functionality in your application.

To learn more about this Multitenancy package, you can check out the source code on GitHub at romegadigital/Multitenancy. To learn how to install and use the package, check out the Multitenency readme file.

See also: Laravel Tenancy – Multi-Tenant Package for Laravel

Filed in: Laravel Packages / multitenency / packages
Laravel News Partners

Laravel Jobs

Backend Software Engineer (PHP Developer)
Austin TX, Bonita Springs FL
Certified eSupport Corp
Laravel Developer
Glendale, CA (COVID Remote)
Jogg, Inc
Full-Stack Engineer (Mid to Senior)
Remote (EST, CST)
Senior Laravel Developer (AI Applications)
Remote from anywhere in the UK or from our London office
GreenShoot Labs
Full Stack Engineer


Join 31,000+ others and never miss out on new tips, tutorials, and more.