From a8f84d280860e003ca00a8e67ce78ec8962bbd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Mon, 2 Dec 2019 17:57:16 +0100 Subject: [PATCH] Accept closures in tenant() helper --- src/helpers.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/helpers.php b/src/helpers.php index 101d43df..3f7f98ab 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -18,14 +18,23 @@ if (! function_exists('tenancy')) { } 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) { - if (! is_null($key)) { - return optional(app(Tenant::class))->get($key) ?? null; + if (is_null($key)) { + 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; } }