3
因此,我写了一个嵌套资源的简单应用程序:帖子和评论。当然,职位是父母,评论是儿童,每个职位与一个职位相关。够简单。现在我要评论索引(和创建,POST)页面生活在posts/{post_id}/comments
,更新(PUT)生活在/posts/{post_id}/comments/{comment_id}
。所以,我想这一点:如何在Laravel 4上路由儿童资源?
Route::resource('posts', 'PostsController');
Route::group(array('prefix' => 'posts/{post_id}'), function() {
Route::resource('comments', 'CommentsController');
});
但由于路线名称注册为posts.{post_id}.comments.create
将无法正常工作。基本上,post_id占位符被视为路线的一部分,并且不是整洁的。任何方式做这个很好,或者我应该只写一个一个路由,并摆脱组/路线::资源/前缀的东西?
当我在CommentsController'''index($ posts){echo $ posts}'''中写这样的东西时,它不显示任何东西? –
我的不好。它工作正常。 –