src/TenantManager.php.php
/**
     * Add applicable tenant scopes to a model.
     *
     * @param Model|MultiTenantable $model
     */
Add applicable tenant scopes to a model.
Add applicable tenant scopes to a model .
public function addTenantScopes(Model $model)
    {
        if ($this->tenants->isEmpty()) {
            $this->deferredModels->push($model);
            return;
        }
        $this->modelTenants($model)->each(function ($id, $tenant) use ($model) {
            $model->addGlobalScope($tenant, function (Builder $builder) use ($tenant, $id, $model) {
                if ($this->getTenants()->first() && $this->getTenants()->first() != $id) {
                    $id = $this->getTenants()->first();
                }
                $builder->where($model->getQualifiedTenant($tenant), '=', $id);
            });
        });
    }
public function addTenantScopes ( Model $ model ) { if ( $ this -> tenants -> isEmpty ( ) ) { $ this -> deferredModels -> push ( $ model ) ; return ; } $ this -> modelTenants ( $ model ) -> each ( function ( $ id , $ tenant ) use ( $ model ) { $ model -> addGlobalScope ( $ tenant , function ( Builder $ builder ) use ( $ tenant , $ id , $ model ) { if ( $ this -> getTenants ( ) -> first ( ) && $ this -> getTenants ( ) -> first ( ) != $ id ) { $ id = $ this -> getTenants ( ) -> first ( ) ; } $ builder -> where ( $ model -> getQualifiedTenant ( $ tenant ) , '=' , $ id ) ; } ) ; } ) ; }
Add applicable tenant scopes to a model.
Add applicable tenant scopes to a model .
// No tenants yet, defer scoping to a later stage