1

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

Guillaume Mercey
  • 391
  • 3
  • 14

1 Answers1

2

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);
hfingler
  • 1,931
  • 4
  • 29
  • 36
  • Thanks for your answer. I tried your example and I get the same result. When I print `$uid` I get `{photos}` instead of the excepted value `1`. – Guillaume Mercey Jun 10 '15 at 20:05
  • How is your URL? How are you redirecting to the page that has the nested resource? – hfingler Jun 10 '15 at 20:06
  • As always, it was a stupid mistake. I just checked how I was generated my route to answer you, when I found out that I forgot to set my `photos` id in my route -_- Thanks for your answers ! – Guillaume Mercey Jun 10 '15 at 20:10