Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/AppServiceProvider.php
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | public function boot() | ||||
/** @var Builder $this */ | /** @var Builder $this */ | ||||
return $this->whereNull(($table ? "$table." : "") . "tenant_id"); | return $this->whereNull(($table ? "$table." : "") . "tenant_id"); | ||||
} | } | ||||
); | ); | ||||
Builder::macro( | Builder::macro( | ||||
'withObjectTenantContext', | 'withObjectTenantContext', | ||||
function (object $object, string $table = null) { | function (object $object, string $table = null) { | ||||
// backend artisan cli | $tenantId = $object->tenant_id; | ||||
if (app()->runningInConsole()) { | |||||
/** @var Builder $this */ | |||||
return $this->where(($table ? "$table." : "") . "tenant_id", $object->tenant_id); | |||||
} | |||||
$subject = auth()->user(); | |||||
if ($subject->role == "admin") { | |||||
/** @var Builder $this */ | |||||
return $this->where(($table ? "$table." : "") . "tenant_id", $object->tenant_id); | |||||
} | |||||
$tenantId = $subject->tenant_id; | |||||
if ($tenantId) { | if ($tenantId) { | ||||
/** @var Builder $this */ | /** @var Builder $this */ | ||||
return $this->where(($table ? "$table." : "") . "tenant_id", $tenantId); | return $this->where(($table ? "$table." : "") . "tenant_id", $tenantId); | ||||
} | } | ||||
/** @var Builder $this */ | /** @var Builder $this */ | ||||
return $this->whereNull(($table ? "$table." : "") . "tenant_id"); | return $this->whereNull(($table ? "$table." : "") . "tenant_id"); | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |