belongsTo(config('tenancy.tenant_model'), static::$tenantIdColumn); } public static function bootBelongsToTenant() { static::addGlobalScope(new TenantScope); static::creating(function ($model) { if (! $model->getAttribute(static::$tenantIdColumn) && ! $model->relationLoaded('tenant')) { if (tenancy()->initialized) { $model->setAttribute(static::$tenantIdColumn, tenant()->getTenantKey()); $model->setRelation('tenant', tenant()); } } }); } }