Laravel 5 - Nest Resource index method resource ID

1.1k views Asked by At

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

1

There are 1 answers

3
hfingler On BEST ANSWER

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);