I made a Route model binding in the RouteServiceProvider
:
public function boot(Router $router)
{
parent::boot($router);
$router->model('article', 'App\Article');
}
My route group:
Route::group(['prefix' => 'articles'], function(){
//some routes ....
Route::group(['prefix' => '{article}'], function(){
Route::get('', [
'as' => 'article.show',
'uses' => 'ArticlesController@show'
]);
Route::get('comments', [
'as' => 'article.comments',
'uses' => 'ArticlesController@comments'
]);
});
});
/articles/666
works perfectly
/articles/666/comments
show me Http not found exception.
I was able to recreate this issue but only when I did not have an article with id of 666 in the database.
Strangely enough, I didn't come across that issue when I did not have my route binding setup.
Try creating an article with id of 666 or changing the id to an article you do have and it should work. If it does not, you may have another route overriding this one. Run the command
php artisan route:list
to get a list of all your routes. If you are caching routes, be sure to regenerate the cache as well.Using your routing you can inject the model directly into the action:
But bear in mind that you need to use the 'bindings' middleware group to ensure that the model gets implicitly from the route. So eg in your routes config:
This is not something that appears well documented.