If I have a route in routes.php that routes to a controller method and there's a variable number of url parameters the controller method needs to access
i.e.
myApp/something/{a}/{b}/...
What's the best practice Laravel way of accessing those url parameters?
I've noticed I can use func_get_args() to get the parameters but wasn't sure if this was best practice.
Thanks for any assistance..
Personally I would just pass all the route parameters into the action method over using func_get_args with that said, coming in Laravel 5 we have FormRequest objects which will contain validation/auth rules aswell as all the URL parameters so your controller actions will look something like:
class ArticleController
{
public function read(ReadArticleRequest $request)
{
// $request will have all url properties
return 'You are reading article ' . $request->articleId . ', slug: ' . $request->articleSlug;
}
}
These FormRequests are going to be an absolute godsend, if you are not ready for production you may want to bump your version up and use the current dev-master branch of Laravel to get early access, we are only a few weeks from release after all.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community