简体   繁体   中英

nested resource controller laravel 4

In laravel 4 i would like to have a nested controller.

I have read the documentation but didn't find any explanation on how to do it.

Supose that in a app i have some articles and each article have his own set of comments. I would like to be able to get all comment of a specific article by accessing a URL like this.

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

I have created a commentsController, but i don't know how to correctly get the article id from the url, so i can pass it to all my CRUD methods in my controller

in route.php

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

in controller

public function show($articleId, $comment) {}

public function create($articleId) {}

I am not sure nested resource controllers are the way to go.... Here is what I would do.

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

Then in your controller

public function comments($id) {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM