Support the ongoing development of Laravel.io →
Requests
Last updated 2 years ago.
0

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

Last updated 5 years ago.
0

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.

0

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

0

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.

0

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 :)

Last updated 5 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.