How to declare unlimited parameters in Laravel?

廉价感情. 提交于 2020-01-12 18:51:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!