public static function bootTenantId() { if (Auth::check()) { if (method_exists(Auth::user(), 'isAdmin') && Auth::user()->isAdmin()) { return TenantScope::setOverride(); } else { return TenantScope::setTenantId(Auth::user()->getTenantId()); } } else { return TenantScope::setOverride(); } }
/** * Sets the tenant id automatically when creating models * * @param Model|ScopedByTenant $model */ public function creating(Model $model) { // If global scope removed from model, silently return if (!$model->hasGlobalScope(new TenantScope())) { return; } // If there is no Tenant set, silently return if (is_null(TenantScope::getTenantId())) { return; } // Otherwise, scope the new model $model->{$model->getTenantColumn()} = TenantScope::getTenantId(); }