mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 12:34:03 +00:00
correct method name
This commit is contained in:
parent
01a3a5fbab
commit
eae2bd607c
5 changed files with 26 additions and 26 deletions
|
|
@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
|||
*/
|
||||
interface SyncMaster extends Syncable
|
||||
{
|
||||
public function resources(): MorphToMany;
|
||||
public function tenants(): MorphToMany;
|
||||
|
||||
public function getTenantModelName(): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ trait ResourceSyncing
|
|||
return true;
|
||||
}
|
||||
|
||||
public function resources(): MorphToMany
|
||||
public function tenants(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany($this->getResourceTenantModelName(), 'tenant_resources', 'tenant_resources', 'resource_global_id', 'tenant_id', 'global_id')
|
||||
->using(TenantPivot::class);
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ class UpdateSyncedResource extends QueueableListener
|
|||
|
||||
// Since this model is "dirty" (taken by reference from the event), it might have the tenants
|
||||
// relationship already loaded and cached. For this reason, we refresh the relationship.
|
||||
$centralModel->load('resources');
|
||||
$centralModel->load('tenants');
|
||||
|
||||
/** @var TenantCollection $tenants */
|
||||
$tenants = $centralModel->resources;
|
||||
$tenants = $centralModel->tenants;
|
||||
|
||||
return $tenants;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ class UpdateSyncedResource extends QueueableListener
|
|||
return ((string) $model->pivot->tenant_id) === ((string) $tenant->getTenantKey());
|
||||
};
|
||||
|
||||
$mappingExists = $centralModel->resources->contains($currentTenantMapping);
|
||||
$mappingExists = $centralModel->tenants->contains($currentTenantMapping);
|
||||
|
||||
if (! $mappingExists) {
|
||||
// Here we should call TenantPivot, but we call general Pivot, so that this works
|
||||
|
|
@ -89,12 +89,12 @@ class UpdateSyncedResource extends QueueableListener
|
|||
/** @var Tenant */
|
||||
$tenant = $event->tenant;
|
||||
|
||||
$centralModel->resources()->attach($tenant->getTenantKey());
|
||||
$centralModel->tenants()->attach($tenant->getTenantKey());
|
||||
});
|
||||
}
|
||||
|
||||
/** @var TenantCollection $tenants */
|
||||
$tenants = $centralModel->resources->filter(function ($model) use ($currentTenantMapping) {
|
||||
$tenants = $centralModel->tenants->filter(function ($model) use ($currentTenantMapping) {
|
||||
// Remove the mapping for the current tenant.
|
||||
return ! $currentTenantMapping($model);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue