1
0
Fork 0
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:
Samuel Štancl 2020-05-12 01:54:02 +02:00
parent daae67c0f7
commit b7c8f1fba7
12 changed files with 488 additions and 56 deletions

View file

@ -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();
}
}
}