php - Laravel - root directory routing behaves strangely in a nested route group -
i have following route definition in laravel 5. when group routes in following way, seems route admin.proposals.home not work if provide "/" path, , work if trailing (like home) provided:
/** * routes system administrators. */ route::group(['prefix' => 'admin', 'middleware' => 'admin'], function() { route::group(['prefix' => 'people'], function() { route::get('/', ['as' => 'admin.people.home', 'uses' => 'personcontroller@index']); route::get('/profile/{username}', ['as' => 'admin.person.profile', 'uses' => 'personcontroller@view']); route::get('/organization/{id}', ['as' => 'admin.people.organization', 'uses' => 'personcontroller@indexbyorganization']); }); route::group(['prefix' => 'projects'], function() { route::get('/', ['as' => 'admin.projects.home', 'uses' => 'projectcontroller@index']); route::get('/{projectid}', ['as' => 'admin.project.view', 'uses' => 'projectcontroller@view']); route::group(['prefix' => 'proposals'], function() { //problematic line below route::get('/home', ['as' => 'admin.proposals.home', 'uses' => 'proposalcontroller@index']); route::get('/{proposalid}', ['as' => 'admin.proposal.view', 'uses' => 'proposalcontroller@view']); }); }); }); specifically, if change line:
route::get('/home', ['as' => 'admin.proposals.home', 'uses' => 'proposalcontroller@index' ]); to:
route::get('/', ['as' => 'admin.proposals.home', 'uses' => 'proposalcontroller@index' ]); i got error saying:
trying property of non-object (view: ... \views\admin\projects\view.blade.php) but, admin.proposals.home route points controllers index() method , has nothing view.blad.php.
changing path get('/home') works perfectly.
what i'm missing?
it's route position order problem.
since have route uri admin/projects/ admin.project.home, , after admin/projects/{projectid} takes precedence on route admin/projects/proposals/
laravel takes proposals projectid.
route::group(['prefix' => 'projects'], function() { route::group(['prefix' => 'proposals'], function() { //problematic line below route::get('/', ['as' => 'admin.proposals.home', 'uses' => 'proposalcontroller@index']); route::get('/{proposalid}', ['as' => 'admin.proposal.view', 'uses' => 'proposalcontroller@view']); }); route::get('/', ['as' => 'admin.projects.home', 'uses' => 'projectcontroller@index']); route::get('/{projectid}', ['as' => 'admin.project.view', 'uses' => 'projectcontroller@view']); }); try order , let me know get. purely it's route order problem.
Comments
Post a Comment