I have a route for tenants name like that:
JavaScript
x
example.test/TenantNameHere
And I want to make the default of my domain start with the word “site”:
JavaScript
example.test/site
My code:
JavaScript
Route::prefix('{tenantName}')->group(function () {
Route::get('/', function ($tenantName) {
return "{$tenantName}";
});
});
Route::prefix('site')->group(function () {
Route::get('price', function () {
return view('welcome');
});
});
Route::redirect('/', 'site', 301);
The problem that I’m facing with this code now is when I open the domain it redirects me to tenantName
route, not to the home page that I made!
How can spreate the route of site
from TenantName
?
Advertisement
Answer
you just have to register your absolute path (‘site’) first, and “wildcards” routes after, because everything you put in url line now hit the first tenantName route
try this (reverse the order):
JavaScript
Route::redirect('/', '/site', 301);
Route::prefix('site')->group(function () {
Route::get('/', function () {
return view('welcome');
});
});
Route::prefix('{tenantName}')->group(function () {
Route::get('/', function ($tenantName) {
return "{$tenantName}";
});
});
also change “/site/price” path to “/site”, so redirect will find correct route