forked from archtechx/tenancy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.php
69 lines (58 loc) · 1.53 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Tenancy;
if (! function_exists('tenancy')) {
/** @return Tenancy */
function tenancy()
{
return app(Tenancy::class);
}
}
if (! function_exists('tenant')) {
/**
* Get a key from the current tenant's storage.
*
* @param string|null $key
* @return Tenant|null|mixed
*/
function tenant($key = null)
{
if (! app()->bound(Tenant::class)) {
return;
}
if (is_null($key)) {
return app(Tenant::class);
}
return optional(app(Tenant::class))->getAttribute($key) ?? null;
}
}
if (! function_exists('tenant_asset')) {
/** @return string */
function tenant_asset($asset)
{
return route('stancl.tenancy.asset', ['path' => $asset]);
}
}
if (! function_exists('global_asset')) {
function global_asset($asset)
{
return app('globalUrl')->asset($asset);
}
}
if (! function_exists('global_cache')) {
function global_cache()
{
return app('globalCache');
}
}
if (! function_exists('tenant_route')) {
function tenant_route(string $domain, $route, $parameters = [], $absolute = true)
{
// replace first occurance of hostname fragment with $domain
$url = route($route, $parameters, $absolute);
$hostname = parse_url($url, PHP_URL_HOST);
$position = strpos($url, $hostname);
return substr_replace($url, $domain, $position, strlen($hostname));
}
}