I don’t think you can have ->name('basket'); twice.
You may have to write middleware that detects the domain Request::getHost(); <- if that still works
It works without any issue, as long as I manually go to the /basket address, so the router can handle it as it uses the correct route.
However it seems when using the named routes in a template or controller it just takes the first route with the correct name without looking to the domain.
Yeah that’s what I figured , you may not be able to use named routes in your project unless you names them name-1-aaa and name-1-bbb and do logic in blade to serve the proper link
Should this be reported as a bug on github or am I doing something completely out of scope here? It is unexpected behaviour to say the least.
Option 1: Don't use named routes in blade: use:
<a href="{{ url('/basket') }}">My Basket</a>
instead of
<a href=" {{route('basket')}}">My Basket</a>
this will use the current domain and link to the basket. Remove the ->name() attached to the route.
Option 2:
Route::get('/basket', function () {
$domain = Request::getHost();
switch ($domain) {
case 'domain-aaa':
return redirect('yourview1');
break;
case 'domain-bbb':
return redirect('yourview2');
//or
return redirect()->action('HomeController@index');
break;
case 2:
return redirect('404');
break;
}
})->name('basket');
hope that helps, good luck :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community