All Projects → sbine → simple-tenancy

sbine / simple-tenancy

Licence: MIT License
Simple multi-tenancy for Laravel apps

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to simple-tenancy

Openwisp Users
Implementation of user management and multi-tenancy for OpenWISP
Stars: ✭ 145 (+302.78%)
Mutual labels:  multi-tenancy
go-saas
go data framework for saas(multi-tenancy)
Stars: ✭ 101 (+180.56%)
Mutual labels:  multi-tenancy
multi-tenant
Spring boot + Hibernate + Postgresql的多租户实现Demo
Stars: ✭ 110 (+205.56%)
Mutual labels:  multi-tenancy
K8spin Operator
K8Spin multi-tenant operator - OSS
Stars: ✭ 175 (+386.11%)
Mutual labels:  multi-tenancy
Loft
Namespace & Virtual Cluster Manager for Kubernetes - Lightweight Virtual Clusters, Self-Service Provisioning for Engineers and 70% Cost Savings with Sleep Mode
Stars: ✭ 239 (+563.89%)
Mutual labels:  multi-tenancy
multi-tenancy-devise
mtdevise adds basecamp style user logins to your ruby on rails application.
Stars: ✭ 27 (-25%)
Mutual labels:  multi-tenancy
Hivedscheduler
Kubernetes Scheduler for Deep Learning
Stars: ✭ 126 (+250%)
Mutual labels:  multi-tenancy
springboot-schema-per-tenant
Seed for achieving multi-tenancy (single pooled schema-per-tenant) using SpringBoot and Hibernate
Stars: ✭ 75 (+108.33%)
Mutual labels:  multi-tenancy
KubeCube
KubeCube is an open source enterprise-level container platform
Stars: ✭ 355 (+886.11%)
Mutual labels:  multi-tenancy
multitenant-microservices-demo
Full Isolation in Multi-Tenant SaaS with Kubernetes + Istio
Stars: ✭ 57 (+58.33%)
Mutual labels:  multi-tenancy
Multi Tenancy
Flux v1: Manage a multi-tenant cluster with Flux and Kustomize
Stars: ✭ 180 (+400%)
Mutual labels:  multi-tenancy
Townhouse
A multi-tenant Laravel app for listing property rentals
Stars: ✭ 218 (+505.56%)
Mutual labels:  multi-tenancy
awesome-multitenancy
No description or website provided.
Stars: ✭ 26 (-27.78%)
Mutual labels:  multi-tenancy
Devicemanager.api
Web API Framework demonstrates scalable, multitenant, architecture and allows building its own solution in the minutes. Uses: Entity Framework, UnitOfWork, Repository patterns. Wrapped in Docker, Kubernetes
Stars: ✭ 168 (+366.67%)
Mutual labels:  multi-tenancy
MongoRepository
An easy-to-configure, powerful repository for MongoDB with support for multi-tenancy
Stars: ✭ 32 (-11.11%)
Mutual labels:  multi-tenancy
Tenancy
Automatic multi-tenancy for Laravel. No code changes needed.
Stars: ✭ 2,133 (+5825%)
Mutual labels:  multi-tenancy
multitenant
Multi-Tenant Spring Boot Application with separate databases using Hibernate and H2.
Stars: ✭ 15 (-58.33%)
Mutual labels:  multi-tenancy
laravel-tenants
Rinvex Tenantable is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others.
Stars: ✭ 78 (+116.67%)
Mutual labels:  multi-tenancy
eixample
Multi-Tenant .NET 6 Architecture (Angular, Vue, React)
Stars: ✭ 61 (+69.44%)
Mutual labels:  multi-tenancy
awesome-landlord
A simple, single database multi-tenancy solution for Laravel 5.2+
Stars: ✭ 41 (+13.89%)
Mutual labels:  multi-tenancy

Simple Laravel Multi-Tenancy

Build status

Simple Tenancy adds automatic multi-tenant support to Eloquent models stored in a shared database.

It requires zero configuration in most cases, relying on established Laravel conventions and a single column on each table.

How it works

Under the hood, it has only 4 components:

  1. Tenant: Keeps track of the current user
  2. HasTenancy: A trait for models belonging to the tenant, which registers:
  3. TenancyScope: A global scope limiting all the model's queries to the current tenant
  4. TenancyObserver: An observer which sets the current tenant column/identifier on save

By default, the tenant is Laravel's Auth::user(), and all tenancy checks are disabled when no one is authenticated.

Installation

  1. Install using Composer:
composer require sbine/simple-tenancy
  1. Add the HasTenancy trait to all models belonging to the tenant:
class Account extends Model
{
    use \Sbine\Tenancy\HasTenancy;
}
  1. Ensure a user_id column exists on the table of every model using the trait.

Customizing the tenant column/ID

If needed, you can customize the name of the tenant column or identifier by extending the Tenant class and binding it into the container:

class MyTenant extends \Sbine\Tenancy\Tenant
{
    /**
     * Retrieve the column identifying each model's tenant.
     */
    public function column()
    {
        return 'tenant_hashid';
    }

    /**
     * Retrieve the current tenant's identifier.
     */
    public function id()
    {
        return $this->user->hashid;
    }
}

Customizing tenancy behavior

By default, if no user is authenticated tenancy will be completely disabled. This is by design so the library doesn't interfere with testing, seeding, and other unauthenticated model usage.

To change the tenancy behavior in any way, you can override the Tenant binding in the application container.

For example, to prevent all querying and saving of tenant models when no one is authenticated:

    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            // Throw an AuthenticationException if auth check fails
            return new \Sbine\Tenancy\Tenant(Auth::authenticate());
        });
    }

To allow overriding tenancy checks based on a policy or method, pass a callback returning true or false:

    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            return new \Sbine\Tenancy\Tenant(Auth::user(), function ($user) {
                return $user->can('admin');
            });
        });
    }

For complete control over tenant behavior, you can bind your own Tenant implementation:

    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            return new MyTenant;
        });
    }

Disabling tenancy

For convenience, a SuperAdmin class is provided which you can bind at any time to disable tenant checks:

    $this->app->singleton(\Sbine\Tenancy\Tenant::class, \Sbine\Tenancy\SuperAdmin::class);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].