mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:34:03 +00:00
[v3] Rename tenant redirect macro (#389)
* [v3] Rename tenant redirect macro * update tests
This commit is contained in:
parent
5972364075
commit
60665517a0
3 changed files with 6 additions and 5 deletions
|
|
@ -226,7 +226,7 @@ return [
|
||||||
// Stancl\Tenancy\Features\Timestamps::class, // https://tenancy.samuelstancl.me/docs/v2/features/timestamps/
|
// Stancl\Tenancy\Features\Timestamps::class, // https://tenancy.samuelstancl.me/docs/v2/features/timestamps/
|
||||||
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancy.samuelstancl.me/docs/v2/features/tenant-config/
|
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancy.samuelstancl.me/docs/v2/features/tenant-config/
|
||||||
// Stancl\Tenancy\Features\TelescopeTags::class, // https://tenancy.samuelstancl.me/docs/v2/telescope/
|
// Stancl\Tenancy\Features\TelescopeTags::class, // https://tenancy.samuelstancl.me/docs/v2/telescope/
|
||||||
// Stancl\Tenancy\Features\TenantRedirect::class, // https://tenancy.samuelstancl.me/docs/v2/features/tenant-redirect/
|
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancy.samuelstancl.me/docs/v2/features/tenant-redirect/
|
||||||
],
|
],
|
||||||
'storage_to_config_map' => [ // Used by the TenantConfig feature
|
'storage_to_config_map' => [ // Used by the TenantConfig feature
|
||||||
// 'paypal_api_key' => 'services.paypal.api_key',
|
// 'paypal_api_key' => 'services.paypal.api_key',
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ use Illuminate\Http\RedirectResponse;
|
||||||
use Stancl\Tenancy\Contracts\Feature;
|
use Stancl\Tenancy\Contracts\Feature;
|
||||||
use Stancl\Tenancy\TenantManager;
|
use Stancl\Tenancy\TenantManager;
|
||||||
|
|
||||||
class TenantRedirect implements Feature
|
class CrossDomainRedirect implements Feature
|
||||||
{
|
{
|
||||||
public function bootstrap(TenantManager $tenantManager): void
|
public function bootstrap(TenantManager $tenantManager): void
|
||||||
{
|
{
|
||||||
RedirectResponse::macro('tenant', function (string $domain) {
|
RedirectResponse::macro('domain', function (string $domain) {
|
||||||
// replace first occurance of hostname fragment with $domain
|
// replace first occurance of hostname fragment with $domain
|
||||||
$url = $this->getTargetUrl();
|
$url = $this->getTargetUrl();
|
||||||
$hostname = parse_url($url, PHP_URL_HOST);
|
$hostname = parse_url($url, PHP_URL_HOST);
|
||||||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Tests;
|
namespace Stancl\Tenancy\Tests;
|
||||||
|
|
||||||
use Route;
|
use Route;
|
||||||
|
use Stancl\Tenancy\Features\CrossDomainRedirect;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
||||||
class RedirectTest extends TestCase
|
class RedirectTest extends TestCase
|
||||||
|
|
@ -16,7 +17,7 @@ class RedirectTest extends TestCase
|
||||||
public function tenant_redirect_macro_replaces_only_the_hostname()
|
public function tenant_redirect_macro_replaces_only_the_hostname()
|
||||||
{
|
{
|
||||||
config([
|
config([
|
||||||
'tenancy.features' => ['Stancl\Tenancy\Features\TenantRedirect'],
|
'tenancy.features' => [CrossDomainRedirect::class],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Route::get('/foobar', function () {
|
Route::get('/foobar', function () {
|
||||||
|
|
@ -24,7 +25,7 @@ class RedirectTest extends TestCase
|
||||||
})->name('home');
|
})->name('home');
|
||||||
|
|
||||||
Route::get('/redirect', function () {
|
Route::get('/redirect', function () {
|
||||||
return redirect()->route('home')->tenant('abcd');
|
return redirect()->route('home')->domain('abcd');
|
||||||
});
|
});
|
||||||
|
|
||||||
Tenant::create('foo.localhost');
|
Tenant::create('foo.localhost');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue