Created
April 17, 2013 07:33
-
-
Save petersuhm/5402443 to your computer and use it in GitHub Desktop.
Laravel 4 nested resources. I had some trouble finding a good way to add nested resources in my routes.php file. Therfore, I thought I would share what I ended up with. Please say so, if you have any improvements to this :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ConversationsController extends BaseController { | |
public function show($user_id, $conversation_id) | |
{ | |
var_dump($user_id); | |
var_dump($conversation_id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::group(array('before' => 'auth'), function() | |
{ | |
Route::group(array('prefix' => 'users/{user_id}'), function() | |
{ | |
Route::resource('conversations', 'ConversationsController', array('only' => array('show'))); | |
}); | |
}); |
Why do you have two nested route grous? Can't you add both the before filter and the prefix to the same group configuration?
You also dont need to prefix like that unless you have a specific reason. The following will work:
Route::resource('users.conversions', 'ConversationsController');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The URL to the show route:
GET /users/1/conversations/43