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:
parent
411d486282
commit
e5700e7f72
2 changed files with 75 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue