mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:34:03 +00:00
Shared users - complete
This commit is contained in:
parent
daae67c0f7
commit
b7c8f1fba7
12 changed files with 488 additions and 56 deletions
|
|
@ -33,6 +33,10 @@ class Tenancy
|
|||
|
||||
public function end(): void
|
||||
{
|
||||
if (! $this->initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->initialized = false;
|
||||
|
||||
event(new Events\TenancyEnded($this));
|
||||
|
|
@ -68,4 +72,28 @@ class Tenancy
|
|||
{
|
||||
return $this->model()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a callback for multiple tenants.
|
||||
* More performant than running $tenant->run() one by one.
|
||||
*
|
||||
* @param Tenant[]|\Illuminate\Support\Collection $tenants
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public function runForMultiple($tenants, callable $callback)
|
||||
{
|
||||
$originalTenant = $this->tenant;
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
$this->initialize($tenant);
|
||||
$callback($tenant);
|
||||
}
|
||||
|
||||
if ($originalTenant) {
|
||||
$this->initialize($originalTenant);
|
||||
} else {
|
||||
$this->end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue