How do I declare unlimited parameters in Laravel?
Is there a way to declare unlimited parameters in Laravel 5 routes like Codeigniter?
I am going to create a large application and it is not possible to declare every parameter in the route file for every function. I tried searching a lot but didn't get any solution.
+3
Nishant kango
source
to share
1 answer
You can use this
//routes.php
Route::get('{id}/{params?}', 'YourController@action')->where('params', '(.*)');
Don't forget to put the above at the very end (bottom) of your route.php file, as it is similar to the catch all route, so you need to define any more specific routes first.
//controller
class YourController extends BaseController {
public function action($id, $params = null)
{
if($params)
{
$params = explode('/', $params);
//do stuff
}
}
}
+4
Lucky saini
source
to share