src/Tenantable.php
public static function bootTenantable()
    {
        static::addGlobalScope('tenant', function (Builder $builder) {
            if ($tenant = config('rinvex.tenantable.tenant')) {
                $builder->whereHas('tenants', function (Builder $builder) use ($tenant) {
                    $key = $tenant instanceof Model ? $tenant->getKeyName() : (is_int($tenant) ? 'id' : 'slug');
                    $value = $tenant instanceof Model ? $tenant->$key : $tenant;
                    $builder->where($key, $value);
                });
            }
        });

        static::created(function (Model $tenantableModel) {
            if ($tenantableModel->queuedTenants) {
                $tenantableModel->attachTenants($tenantableModel->queuedTenants);

                $tenantableModel->queuedTenants = [];
            }
        });

        static::deleted(function (Model $tenantableModel) {
            $tenantableModel->tenants()->detach();
        });
    }
public static function bootTenantable()
    {
        static::addGlobalScope('tenant', function (Builder $builder) {
            if ($tenant = config('rinvex.tenantable.tenant')) {
                $builder->whereHas('tenants', function (Builder $builder) use ($tenant) {
                    $key = $tenant instanceof Model ? $tenant->getKeyName() : (is_int($tenant) ? 'id' : 'slug');
                    $value = $tenant instanceof Model ? $tenant->$key : $tenant;
                    $builder->where($key, $value);
                });
            }
        });

        static::created(function (Model $tenantableModel) {
            if ($tenantableModel->queuedTenants) {
                $tenantableModel->attachTenants($tenantableModel->queuedTenants);

                $tenantableModel->queuedTenants = [];
            }
        });

        static::deleted(function (Model $tenantableModel) {
            $tenantableModel->tenants()->detach();
        });
    }
public static function bootTenantable ( ) { static :: addGlobalScope ( 'tenant' , function ( Builder $ builder ) { if ( $ tenant = config ( 'rinvex.tenantable.tenant' ) ) { $ builder -> whereHas ( 'tenants' , function ( Builder $ builder ) use ( $ tenant ) { $ key = $ tenant instanceof Model ? $ tenant -> getKeyName ( ) : ( is_int ( $ tenant ) ? 'id' : 'slug' ) ; $ value = $ tenant instanceof Model ? $ tenant -> $ key : $ tenant ; $ builder -> where ( $ key , $ value ) ; } ) ; } } ) ; static :: created ( function ( Model $ tenantableModel ) { if ( $ tenantableModel -> queuedTenants ) { $ tenantableModel -> attachTenants ( $ tenantableModel -> queuedTenants ) ; $ tenantableModel -> queuedTenants = [ ] ; } } ) ; static :: deleted ( function ( Model $ tenantableModel ) { $ tenantableModel -> tenants ( ) -> detach ( ) ; } ) ; }
Boot the tenantable trait for a model.

@return void
Boot the tenantable trait for a model .