public function index ($user_id = null)
{
// Retrieve from user if user_id not null, everything otherwise :)
}
Jul 9, 2015
2
Level 50
Get route parameters from the request object
Hello.
Let presume I have a PostsController with an index() method which responds to 2 routes:
- /posts
- /users/{id}/posts
When it responds to the /posts route I want to return all posts paginated. When it responds to the /users/{id}/posts it should return all posts for that user paginated.
The difference is the index() method signature. If there is a user, I will need to accept an argument, but there may not be a user and then I don't need an argument in the method. Is there a way to get route parameters from the request object, so I can check and see if such a parameter exists do that, else do that.
Level 56
1 like
Please or to participate in this conversation.