The question title is the most explicit I could think of, but here's a use case/example for clarity's sake:
Say I define the following route to show an article:
Route::get('article/{slug}/{id}', 'ArticleController@show');
...
class ArticleController extends BaseController {
public function show($id)
{
return View::make('article')->with('article', Article::find($id));
}
}
This won't work, as show
will misake the $id
parameter with the $slug
parameter. Is there a way to pass only the $id
parameter to the show
method?
I dont know if you still look for solution or not, but as I had the same problem and I didn't like these solutions, I did this:
in the your ArticleController
you overload the callAction($method, $parameters)
method, this is a method in Laravel controller class, so it looks like this:
public function callAction($method, $parameters)
{
unset($parameters['id']);
unset($parameters['slug']);
return parent::callAction($method, $parameters);
}
after this you ca easily do this:
public function show($id)
{
return View::make('article')->with('article', Article::find($id));
}
It's possible to manually call controller functions:
Route::get('article/{slug}/{id}', function($slug, $id)
{
return App::make('ArticleController')->show($id);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With