Nested laravel 4 resource controller

In laravel 4, I would like to have a nested controller.

I read the documentation but did not find any explanation on how to do this.

Suppose I have several articles in the application, and each article has its own set of comments. I would like to be able to get comments on a specific article by referring to a URL like this.

http://myapp.com/articles/5/comments

I created a commentController, but I don’t know how to get the article id from the URL correctly, so I can pass it to all my CRUD methods in my controller

+4
source share
2 answers

in route.php

Route::resource('articles.comments','commentsController'); 

in the controller

 public function show($articleId, $comment) {} public function create($articleId) {} 
+5
source

I'm not sure if nested resource controllers are the way ... Here is what I would like to do.

 Route::resource('articles','articlesController'); Route::get('articles/{$id}/comments',' articlesController@comments '); 

Then in your controller

 public function comments($id) { } 
0
source

All Articles