mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue