【发布时间】:2013-05-19 10:58:43
【问题描述】:
在 Laravel 4 中,我希望创建一组 restful 资源如下:
http://localhost/posts/1/comments
http://localhost/posts/1/comments/1
http://localhost/posts/1/comments/1/edit
...
所以我创建了两个控制器:PostsController和CommentsController(在同一层),路由写如下:
Route::resource('posts', 'PostsController');
Route::resource('posts.comments', 'CommentsController');
我还在 /views/cmets/index.blade.php 中创建了一个引用路由的链接:posts.cmets.create
{{ link_to_route('posts.comments.create', 'Add new comment') }}
这是我遇到的问题:
访问http://localhost/posts/1/comments时,页面抛出MissingMandatoryParametersException,提示:
缺少一些强制参数(“posts”)来为路由“posts.cmets.create”生成 URL。
我该如何解决这个问题,我如何知道该解决方案是否也适用于 CommentsController 中的 create 和 edit 方法?
例如
public function index()
{
$tasks = $this->comment->all();
return View::make('comments.index', compact('comments'));
}
public function create()
{
return View::make('comments.create');
}
public function show($post_id,$comment_id)
{
$comment = $this->comment->findOrFail($comment_id);
return View::make('comments.show', compact('comment'));
}
【问题讨论】:
标签: php laravel laravel-4 restful-url