mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
fix #854
This commit is contained in:
parent
065b029f48
commit
24146b26e2
7 changed files with 17 additions and 13 deletions
|
|
@ -12,11 +12,9 @@ use Stancl\Tenancy\Database\TenantScope;
|
|||
*/
|
||||
trait BelongsToTenant
|
||||
{
|
||||
public static $tenantIdColumn = 'tenant_id';
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(config('tenancy.tenant_model'), BelongsToTenant::$tenantIdColumn);
|
||||
return $this->belongsTo(config('tenancy.tenant_model'), config('tenancy.single_db.tenant_id_column'));
|
||||
}
|
||||
|
||||
public static function bootBelongsToTenant(): void
|
||||
|
|
@ -24,9 +22,9 @@ trait BelongsToTenant
|
|||
static::addGlobalScope(new TenantScope);
|
||||
|
||||
static::creating(function ($model) {
|
||||
if (! $model->getAttribute(BelongsToTenant::$tenantIdColumn) && ! $model->relationLoaded('tenant')) {
|
||||
if (! $model->getAttribute(config('tenancy.single_db.tenant_id_column')) && ! $model->relationLoaded('tenant')) {
|
||||
if (tenancy()->initialized) {
|
||||
$model->setAttribute(BelongsToTenant::$tenantIdColumn, tenant()->getTenantKey());
|
||||
$model->setAttribute(config('tenancy.single_db.tenant_id_column'), tenant()->getTenantKey());
|
||||
$model->setRelation('tenant', tenant());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ trait HasScopedValidationRules
|
|||
{
|
||||
public function unique($table, $column = 'NULL')
|
||||
{
|
||||
return (new Unique($table, $column))->where(BelongsToTenant::$tenantIdColumn, $this->getTenantKey());
|
||||
return (new Unique($table, $column))->where(config('tenancy.single_db.tenant_id_column'), $this->getTenantKey());
|
||||
}
|
||||
|
||||
public function exists($table, $column = 'NULL')
|
||||
{
|
||||
return (new Exists($table, $column))->where(BelongsToTenant::$tenantIdColumn, $this->getTenantKey());
|
||||
return (new Exists($table, $column))->where(config('tenancy.single_db.tenant_id_column'), $this->getTenantKey());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use Stancl\Tenancy\Resolvers\Contracts\CachedTenantResolver;
|
|||
trait InvalidatesResolverCache
|
||||
{
|
||||
/** @var array<class-string<CachedTenantResolver>> */
|
||||
public static $resolvers = [
|
||||
public static $resolvers = [ // todo@deprecated, move this to a config key? related to a todo in InvalidatesTenantsResolverCache
|
||||
Resolvers\DomainTenantResolver::class,
|
||||
Resolvers\PathTenantResolver::class,
|
||||
Resolvers\RequestDataTenantResolver::class,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TenantScope implements Scope
|
|||
return;
|
||||
}
|
||||
|
||||
$builder->where($model->qualifyColumn(BelongsToTenant::$tenantIdColumn), tenant()->getTenantKey());
|
||||
$builder->where($model->qualifyColumn(config('tenancy.single_db.tenant_id_column')), tenant()->getTenantKey());
|
||||
}
|
||||
|
||||
public function extend(Builder $builder): void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue