Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bogardo's avatar

Filter on Group Domain Route is eating the dynamic url variable

I have a my routes.php setup like this:

Route::group(['domain' => '{domain}.example.com', 'before' => 'registerdomain'], function()
{
    Route::get('profiles', ['as' => 'profiles.index', 'uses' => 'ProfilesController@index']);
    Route::get('profiles/{slug}', ['as' => 'profiles.show', 'uses' => 'ProfilesController@show']);
});

Route::filter('registerdomain', function($route)
{
    $subdomain = $route->getParameter('domain');

    $organisation = Organisation::where('slug', '=', $subdomain)->first();

    Session::put('organisation', $organisation);
});

And a Controller:

class ProfilesController extends BaseController {

 public function index()
 {
     return 'Profiles Index';
 }

 public function show($slug)
 {
    return 'Profile show for: ' . $slug;
 }

}

When I go to http://acme.example.com/profiles/bogardo, the $slug in the show method returns "acme" instead of "bogardo".

If I change the show method to:

 public function show($domain, $slug)
 {
    return 'Profile show for: ' . $slug;
 }

Then $slug does return "bogardo", and $domain returns "acme".

All my application routes will be placed in the route group and I really don't want to add $domain to every method with url parameters. How can this be avoided? Or does anyone have a better solution for this kind of multisite setup?

0 likes
0 replies

Please or to participate in this conversation.