如何在Laravel中声明无限的参数? [英] How to declare unlimited parameters in Laravel?
本文介绍了如何在Laravel中声明无限的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Laravel 5类似于Codeigniter的路由中,有没有办法声明无限数量的参数?
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.
推荐答案
您可以使用此
//routes.php
Route::get('{id}/{params?}', 'YourController@action')->where('params', '(.*)');
请记住,将以上内容放在route.php文件的最底端(底部),因为它就像一条全部捕获"路由,因此您必须首先定义所有更具体的"路由.
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
}
}
}
这篇关于如何在Laravel中声明无限的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文