mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:44:04 +00:00
Simplify Tenant contract (remove run method), move run logic to Tenancy, add generics
This commit is contained in:
parent
32a063b834
commit
af3b693dd1
9 changed files with 39 additions and 26 deletions
|
|
@ -22,7 +22,7 @@ class CreateTenantResource extends QueueableListener
|
|||
{
|
||||
$tenantResourceClass = $event->centralResource->getTenantModelName();
|
||||
|
||||
$event->tenant->run(function () use ($event, $tenantResourceClass) {
|
||||
tenancy()->run($event->tenant, function () use ($event, $tenantResourceClass) {
|
||||
// Prevent $tenantResourceClass::create() from firing the SyncedResourceSaved event
|
||||
// Manually fire the SyncedResourceSavedInForeignDatabase event instead
|
||||
$tenantResourceClass::withoutEvents(function () use ($event, $tenantResourceClass) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,6 @@ class DeleteResourceInTenant extends QueueableListener
|
|||
|
||||
public function handle(CentralResourceDetachedFromTenant $event): void
|
||||
{
|
||||
$event->tenant->run(fn () => $this->deleteSyncedResource($event->centralResource, true));
|
||||
tenancy()->run($event->tenant, fn () => $this->deleteSyncedResource($event->centralResource, true));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\ResourceSyncing;
|
||||
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphPivot;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
|
||||
/**
|
||||
* Used on pivot models.
|
||||
|
|
@ -31,7 +31,7 @@ trait TriggerSyncingEvents
|
|||
* @var static&Pivot $pivot
|
||||
* @var SyncMaster|null $centralResource
|
||||
* @var (Tenant&Model)|null $tenant
|
||||
*/
|
||||
*/
|
||||
[$centralResource, $tenant] = $pivot->getCentralResourceAndTenant();
|
||||
|
||||
if ($tenant && $centralResource?->shouldSync()) {
|
||||
|
|
@ -44,7 +44,7 @@ trait TriggerSyncingEvents
|
|||
* @var static&Pivot $pivot
|
||||
* @var SyncMaster|null $centralResource
|
||||
* @var (Tenant&Model)|null $tenant
|
||||
*/
|
||||
*/
|
||||
[$centralResource, $tenant] = $pivot->getCentralResourceAndTenant();
|
||||
|
||||
if ($tenant && $centralResource?->shouldSync()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue