mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:34:04 +00:00
[2.3.0] tenant_route() helper (#229)
* Add tenant_route helper * Add tests * Remove redundant setUp() * Fix test namespaces * Apply fixes from StyleCI
This commit is contained in:
parent
4e477b472f
commit
fd00be646e
4 changed files with 36 additions and 10 deletions
|
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\TenantManager;
|
||||
|
||||
if (! \function_exists('tenancy')) {
|
||||
if (! function_exists('tenancy')) {
|
||||
/** @return TenantManager|mixed */
|
||||
function tenancy($key = null)
|
||||
{
|
||||
|
|
@ -17,7 +17,7 @@ if (! \function_exists('tenancy')) {
|
|||
}
|
||||
}
|
||||
|
||||
if (! \function_exists('tenant')) {
|
||||
if (! function_exists('tenant')) {
|
||||
/** @return Tenant|mixed */
|
||||
function tenant($key = null)
|
||||
{
|
||||
|
|
@ -29,7 +29,7 @@ if (! \function_exists('tenant')) {
|
|||
}
|
||||
}
|
||||
|
||||
if (! \function_exists('tenant_asset')) {
|
||||
if (! function_exists('tenant_asset')) {
|
||||
/** @return string */
|
||||
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)
|
||||
{
|
||||
return app('globalUrl')->asset($asset);
|
||||
}
|
||||
}
|
||||
|
||||
if (! \function_exists('global_cache')) {
|
||||
if (! function_exists('global_cache')) {
|
||||
function global_cache()
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue