1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:54:04 +00:00

Merge branch 'master' into shared-users

This commit is contained in:
Samuel Štancl 2020-05-13 00:33:27 +02:00 committed by GitHub
commit 8915297c30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
85 changed files with 880 additions and 3280 deletions

View file

@ -77,15 +77,25 @@ class Tenancy
* Run a callback for multiple tenants.
* More performant than running $tenant->run() one by one.
*
* @param Tenant[]|\Illuminate\Support\Collection $tenants
* @param Tenant[]|\Traversable|string[]|null $tenants
* @param callable $callback
* @return void
*/
public function runForMultiple($tenants, callable $callback)
{
// Wrap string in array
$tenants = is_string($tenants) ? [$tenants] : $tenants;
// Use all tenants if $tenants is falsy
$tenants = $tenants ?: $this->model()->cursor();
$originalTenant = $this->tenant;
foreach ($tenants as $tenant) {
if (is_string($tenant)) {
$tenant = $this->find($tenant);
}
$this->initialize($tenant);
$callback($tenant);
}