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

Accept closures in tenant() helper

This commit is contained in:
Samuel Štancl 2019-12-02 17:57:16 +01:00
parent fd00be646e
commit a8f84d2808

View file

@ -18,14 +18,23 @@ if (! function_exists('tenancy')) {
} }
if (! function_exists('tenant')) { if (! function_exists('tenant')) {
/** @return Tenant|mixed */ /**
* Get a key from the current tenant's storage.
*
* @param string|Closure|null $key
* @return Tenant|mixed
*/
function tenant($key = null) function tenant($key = null)
{ {
if (! is_null($key)) { if (is_null($key)) {
return optional(app(Tenant::class))->get($key) ?? null; return app(Tenant::class);
} }
return app(Tenant::class); if ($key instanceof Closure) {
return app(Tenant::class)->run($key);
}
return optional(app(Tenant::class))->get($key) ?? null;
} }
} }