The following route works fine:
Route::get('/{category}/{product?}/{id?}',array('uses' => 'ProductController@index'));
so all the following url's gets me back my views correctly:
localhost:8000/bookstall/
localhost:8000/bookstall/cds
localhost:8000/bookstall/cds/1234
I am trying to write a api route which returns json response with same route as below:
Route::get('/api/v1/{category}/{product?}/{id?}',array('uses' => 'ProductApiController@index'));
so have these route url's that behave differently:
localhost:8000/api/v1/bookstall/ - This returns 404 page not found
localhost:8000/api/v1/bookstall/cds - This works
localhost:8000//api/v1/bookstall/cds/1234 - This works
Not sure why I am getting 404 page not found in the second API route when a similar route works in the first case. Anything I am missing?
Try to put this route,
Route::get('/api/v1/{category}/{product?}/{id?}',array('uses' => 'ProductApiController@index'));
above
Route::get('/{category}/{product?}/{id?}',array('uses' => 'ProductController@index'));
Thank you that did solve it. Curious why the order is important for this to work?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community