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

Add tenant_route helper

This commit is contained in:
Samuel Štancl 2019-11-20 08:15:28 +01:00
parent f34986b29f
commit 4df358fe3a

View file

@ -5,7 +5,7 @@ declare(strict_types=1);
use Stancl\Tenancy\Tenant; use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\TenantManager; use Stancl\Tenancy\TenantManager;
if (! \function_exists('tenancy')) { if (! function_exists('tenancy')) {
/** @return TenantManager|mixed */ /** @return TenantManager|mixed */
function tenancy($key = null) function tenancy($key = null)
{ {
@ -17,7 +17,7 @@ if (! \function_exists('tenancy')) {
} }
} }
if (! \function_exists('tenant')) { if (! function_exists('tenant')) {
/** @return Tenant|mixed */ /** @return Tenant|mixed */
function tenant($key = null) function tenant($key = null)
{ {
@ -29,7 +29,7 @@ if (! \function_exists('tenant')) {
} }
} }
if (! \function_exists('tenant_asset')) { if (! function_exists('tenant_asset')) {
/** @return string */ /** @return string */
function tenant_asset($asset) function tenant_asset($asset)
{ {
@ -37,16 +37,30 @@ if (! \function_exists('tenant_asset')) {
} }
} }
if (! \function_exists('global_asset')) { if (! function_exists('global_asset')) {
function global_asset($asset) function global_asset($asset)
{ {
return app('globalUrl')->asset($asset); return app('globalUrl')->asset($asset);
} }
} }
if (! \function_exists('global_cache')) { if (! function_exists('global_cache')) {
function global_cache() function global_cache()
{ {
return app('globalCache'); return app('globalCache');
} }
} }
if (! function_exists('tenant_route')) {
function tenant_route(string $route, array $parameters = [], string $domain = null): string
{
$domain = $domain ?? request()->getHost();
// replace first occurance of hostname fragment with $domain
$url = route($route, $parameters);
$hostname = parse_url($url, PHP_URL_HOST);
$position = strpos($url, $hostname);
return substr_replace($url, $domain, $position, strlen($hostname));
}
}