问题
Is there any way to declare unlimited number of parameters in routes of Laravel 5 similar to Codeigniter?
I am going to build a large application and declaring each and every parameter in route file for each function is not possible. I tried searching a lot but didn't got any solution.
回答1:
You can use this
//routes.php
Route::get('{id}/{params?}', 'YourController@action')->where('params', '(.*)');
Remember to put the above on the very end (bottom) of routes.php file as it is like a 'catch all' route, so you have to have all the 'more specific' routes defined first.
//controller
class YourController extends BaseController {
public function action($id, $params = null)
{
if($params)
{
$params = explode('/', $params);
//do stuff
}
}
}
来源:https://stackoverflow.com/questions/31407827/how-to-declare-unlimited-parameters-in-laravel