Reputation: 409
I try to make a default controller base on the Laravel Restful Controller, and I'm block with the index
method with Nested Resources
.
I have a route Route::resource('photos.comments', 'DefaultController');
and I need to get the photo_id
in my index
method. But so fare, I only get {photos}
.
public function index(Request $request)
{
// $request->route('photos) => {photos}
}
or
public function index(Request $request, $photosId)
{
// photosId => {photos}
}
What am I missing ?
Thanks
Upvotes: 1
Views: 1094
Reputation: 2004
Apparently you're doing it right. What do you mean when you say you get {photos}
? Is the photo_id
in the URL? Like photos/1/comments
?
Here's how I do it and it works:
route.php
Route::resource('users.stuff' ,'StuffController');
StuffController.php
public function index($uid, Request $request)
{
//$uid contains the user id that is in the URL
User::find($uid)->doSomeStuff();
dd($uid);
Upvotes: 2