Brightside
Brightside

Reputation: 131

laravel 4 - wrong id out of 2 id's within the routes

I am trying to work my way with this route:

user/1/post/10

and within the posts controller (inside the show function) i try to get the $id of the post but i get the user id (1).

routes:

Route::resource('users.posts', 'PostsController');

and here is my function within post controller:

public function show($id)
{
    dd($id);//output 1
}

Upvotes: 0

Views: 160

Answers (1)

The Alpha
The Alpha

Reputation: 146201

You may try this:

public function show($user_id, $post_id)
{
    dd($post_id); // 10
}

Both parameters will be passed to child resource controller method (show) and the first parameter is the parent id and the second one is child id.

Upvotes: 1

Related Questions