Laravel 5:成组的路由模型绑定 [英] Laravel 5: Route model binding in a group
问题描述
我在RouteServiceProvider
中创建了一个Route模型绑定:
I made a Route model binding in the RouteServiceProvider
:
public function boot(Router $router)
{
parent::boot($router);
$router->model('article', 'App\Article');
}
我的路线组:
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
完美运行
/articles/666/comments
向我显示Http找不到异常.
/articles/666/comments
show me Http not found exception.
推荐答案
仅当我在数据库中没有ID为666的文章时,我才能重新创建此问题.
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.
尝试创建ID为666的文章,或将ID更改为您已有的文章,它应该可以工作.如果不是,则可能有另一条路由覆盖了该路由.运行命令php artisan route:list
以获得所有路由的列表.如果要缓存路由,请确保也重新生成缓存.
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.
这篇关于Laravel 5:成组的路由模型绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!