Oct 31, 2014
0
Level 8
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?
Please or to participate in this conversation.