Skip to content

Commit b898364

Browse files
committed
Add runNonTenantTask method in Tenancy helper to enable running of non-tenant tasks in tenant bound environment
1 parent 067d706 commit b898364

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Tenancy.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Miracuthbert\Multitenancy;
44

5+
use Closure;
56
use Miracuthbert\Multitenancy\Traits\TenancyDriverTrait;
67

78
class Tenancy
@@ -50,6 +51,33 @@ public function tenant()
5051
return $this->manager()->getTenant();
5152
}
5253

54+
/**
55+
* Carry out non-tenant tasks and resume tenant session when done.
56+
*
57+
* @return mixed
58+
*/
59+
public function runNonTenantTask(Closure $callable)
60+
{
61+
$tenant = $this->manager()->getTenant();
62+
63+
$this->manager()->clearTenant();
64+
65+
$callable();
66+
67+
$this->setTenant($tenant);
68+
}
69+
70+
/**
71+
* Set tenant for session or request.
72+
*
73+
* @param \Miracuthbert\Multitenancy\Models\Tenant $tenant
74+
* @return void
75+
*/
76+
public function setTenant($tenant)
77+
{
78+
$this->manager()->setTenant($tenant);
79+
}
80+
5381
/**
5482
* Get an instance of the tenant config helper.
5583
*

0 commit comments

Comments
 (0)