I have four routes on my picture gallery app. They all do the same: query the database and render pictures. The only difference between them is the order of the records. For example:
http://example.com/favorites : shows pics ordered by favorites http://example.com/random : shows pics ordered by random http://example.com/votes : shows pics ordered by votes http://example.com/views : shows pics ordered by views For this, I want to use ONE action in my gallery controller and pass the order as a parameter.
I know I can create this route:
Route::get('/{orderby}', 'GalleryController@showPics') Then get the parameter from the controller:
class GalleryController extends BaseController { public function showPics($orderby) { //query model ordering by $orderby and render the view } } The problem is I don't want to capture example.com/whatever, only those four specific routes.
Is it there a way to pass a parameter to a controller action from the route. Or, alternatively, to read the current accessed route from the controller?