Laravel 4 では、次のように一連の安らかなリソースを作成したいと考えています。
http://localhost/posts/1/comments
http://localhost/posts/1/comments/1
http://localhost/posts/1/comments/1/edit
...ということで、 PostsControllerとCommentsController
の
2 つのコントローラーを(同じレイヤーに) 作成し、ルートは次のように記述します。
Route::resource('posts', 'PostsController');
Route::resource('posts.comments', 'CommentsController');
/views/comments/index.blade.php にもルートを参照するリンクを作成しました: posts.comments.create
{{ link_to_route('posts.comments.create', 'Add new comment') }}
ここに私が会った問題があります:
にアクセスすると、ページでMissingMandatoryParametersExceptionhttp://localhost/posts/1/comments
がスローされ、次のことが示されます。
ルート「posts.comments.create」の URL を生成するためのいくつかの必須パラメーター (「posts」) が欠落しています。
問題を解決するにはどうすればよいですか? また、この解決策が 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'));
}