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