1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 09:34:04 +00:00

Add runGlobal helper

Signed-off-by: michael lundbøl <michael.lundboel@gmail.com>
This commit is contained in:
michael lundbøl 2020-10-24 05:29:41 +02:00
parent 411d486282
commit e5700e7f72
No known key found for this signature in database
GPG key ID: 213C976E2CFD1CAF
2 changed files with 75 additions and 0 deletions

View file

@ -85,6 +85,27 @@ class Tenancy
return array_map('app', $resolve($this->tenant));
}
/**
* @param callable $callback
* @return mixed
*/
public function runGlobal(callable $callback)
{
$oldTenant = $this->tenant;
if ($this->initialized) {
$this->end();
}
$result = $callback();
if ($oldTenant) {
$this->initialize($oldTenant);
}
return $result;
}
public function query(): Builder
{
return $this->model()->query();