Laravel 4: how to write the correct nested controller for nested resource?

十年热恋 提交于 2019-12-05 19:37:56

I'm using nested controllers in two projects, love them. The problem seems to be in your controller and route link.

In the CommentsController, the $post_id is missing. Do something like this:

public function create($post_id)
{
   return View::make('comments.create')
    ->with('post_id', $post_id);
}

When creating links to a nested controller, the ID's of all of the ancestors must be provided. In this case the $post_id is again missing. You may have to make it available to your view if it's not already.

{{ HTML::linkRoute('posts.comments.create', 'Add new comment', $post_id) }}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!