I hope this turns out to be a simple situation that I just forgot in the documentation. I am refactoring our web application to use bullet in urls. Our company allows you to register many organizations, each of which has its own page and auxiliary pages. I am trying to do something like below:
Route::get('/{organization-slug}', 'OrganizationController@index');
Route::get('/{organization-slug}/{organization-subpage-slug}', 'OrganizationController@subpage');
Route::get('/', 'IndexController@index');
Route::get('/dashboard', 'DashboardController@index');
However, how can I do this without contradicting other routes? For example, if I have it '/{organization-slug}'
, it will also match any root level path. Therefore, if the user navigates to /dashboard
, they will be redirected to OrganizationController@index
insteadDashboardController@index
Does laravel have built-in functions to handle this situation?
EDIT
In response to some of the answers that say that the order of the route files is something that needs to be reviewed. I created a new laravel project to test this and added the following routes to/routes/web.php
Route::get('/{some_id}', function($some_id){
echo $some_id;
});
Route::get('/{some_id}/{another_id}', function($some_id, $another_id){
echo $some_id . ' - ' . $another_id;
});
Route::get('/hardcoded/subhard', function(){
echo 'This is the value returned from hardcoded url with sub directory';
});
Route::get('/hardcoded', function(){
echo 'This is the value returned from hardcoded url';
});
Routes /hardcoded/subhard
and are /hardcoded
never reached. When is this order used. However, if we move static routes above dynamic, as shown below:
Route::get('/hardcoded/subhard', function(){
echo 'This is the value returned from hardcoded url with sub directory';
});
Route::get('/hardcoded', function(){
echo 'This is the value returned from hardcoded url';
});
Route::get('/{some_id}', function($some_id){
echo $some_id;
});
Route::get('/{some_id}/{another_id}', function($some_id, $another_id){
echo $some_id . ' - ' . $another_id;
});
Then the corresponding routes work as expected. Is it correct?