mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 13:24:02 +00:00
Make tenants relationship name configurable using the getTenantsRelationshipName()) method in SyncMaster
This commit is contained in:
parent
62624275cc
commit
fc809ba55f
7 changed files with 87 additions and 20 deletions
|
|
@ -8,10 +8,13 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Stancl\Tenancy\Database\Concerns\CentralConnection;
|
||||
use Stancl\Tenancy\ResourceSyncing\ResourceSyncing;
|
||||
use Stancl\Tenancy\ResourceSyncing\SyncMaster;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Stancl\Tenancy\ResourceSyncing\TenantMorphPivot;
|
||||
|
||||
class CentralUser extends Model implements SyncMaster
|
||||
{
|
||||
use ResourceSyncing, CentralConnection;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
|
@ -29,6 +32,19 @@ class CentralUser extends Model implements SyncMaster
|
|||
return TenantUser::class;
|
||||
}
|
||||
|
||||
public function getTenantsRelationshipName(): string
|
||||
{
|
||||
return 'tenants';
|
||||
}
|
||||
|
||||
|
||||
public function tenants(): BelongsToMany
|
||||
{
|
||||
return $this->morphToMany(config('tenancy.models.tenant'), 'tenant_resources', 'tenant_resources', 'resource_global_id', 'tenant_id', $this->getGlobalIdentifierKeyName())
|
||||
->using(TenantMorphPivot::class);
|
||||
}
|
||||
|
||||
|
||||
public function shouldSync(): bool
|
||||
{
|
||||
return static::$shouldSync;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue