mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 22:24:03 +00:00
wip
This commit is contained in:
parent
db4a795c3e
commit
25f19c2c39
2 changed files with 26 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||||
use Stancl\Tenancy\Tenancy;
|
use Stancl\Tenancy\Tenancy;
|
||||||
|
|
||||||
if (! function_exists('tenancy')) {
|
if (! function_exists('tenancy')) {
|
||||||
|
|
@ -59,7 +60,7 @@ if (! function_exists('global_cache')) {
|
||||||
if (! function_exists('tenant_route')) {
|
if (! function_exists('tenant_route')) {
|
||||||
function tenant_route(string $domain, $route, $parameters = [], $absolute = true)
|
function tenant_route(string $domain, $route, $parameters = [], $absolute = true)
|
||||||
{
|
{
|
||||||
// replace first occurance of hostname fragment with $domain
|
// replace first occurrence of hostname fragment with $domain
|
||||||
$url = route($route, $parameters, $absolute);
|
$url = route($route, $parameters, $absolute);
|
||||||
$hostname = parse_url($url, PHP_URL_HOST);
|
$hostname = parse_url($url, PHP_URL_HOST);
|
||||||
$position = strpos($url, $hostname);
|
$position = strpos($url, $hostname);
|
||||||
|
|
@ -67,3 +68,15 @@ if (! function_exists('tenant_route')) {
|
||||||
return substr_replace($url, $domain, $position, strlen($hostname));
|
return substr_replace($url, $domain, $position, strlen($hostname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('tenant_path_route')) {
|
||||||
|
function tenant_path_route($route, $parameters = [])
|
||||||
|
{
|
||||||
|
if (! array_key_exists(PathTenantResolver::$tenantParameterName, $parameters)) {
|
||||||
|
$parameters[PathTenantResolver::$tenantParameterName] = optional(tenant())->getTenantKey();
|
||||||
|
}
|
||||||
|
dd($parameters);
|
||||||
|
|
||||||
|
return route($route, $parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ beforeEach(function () {
|
||||||
], function () {
|
], function () {
|
||||||
Route::get('/foo/{a}/{b}', function ($a, $b) {
|
Route::get('/foo/{a}/{b}', function ($a, $b) {
|
||||||
return "$a + $b";
|
return "$a + $b";
|
||||||
});
|
})->name('foo');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -123,3 +123,14 @@ test('tenant parameter name can be customized', function () {
|
||||||
->withoutExceptionHandling()
|
->withoutExceptionHandling()
|
||||||
->get('/acme/foo/abc/xyz');
|
->get('/acme/foo/abc/xyz');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('tenant path route helper function test', function () {
|
||||||
|
Tenant::create([
|
||||||
|
'id' => 'acme',
|
||||||
|
]);
|
||||||
|
|
||||||
|
pest()->get( tenant_path_route('foo', ['a' => 'a', 'b' => 'b']));
|
||||||
|
|
||||||
|
expect(tenancy()->initialized)->toBeTrue();
|
||||||
|
expect(tenant('id'))->toBe('acme');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue