在 laravel 5 中通配符到错误控制器的路由

Posted

技术标签:

【中文标题】在 laravel 5 中通配符到错误控制器的路由【英文标题】:Wildcard a route to error controller in laravel 5 【发布时间】:2015-11-16 17:13:40 【问题描述】:

我想在 Laravel 5 中使用通配符,也许可以做一些类似的事情:

Route::any('(.*)', 'ErrorController@index');

但我似乎无法让它发挥作用。似乎是其他人遇到的问题。提前致谢。

编辑

我找到了一种解决方法,但必须有更好的解决方案。

Route::get('/one', 'ErrorController@index');
Route::get('/one/two', 'ErrorController@index'); 
Route::get('/one/two/three', 'ErrorController@index'); 
Route::get('/one/two/three/four', 'ErrorController@index'); 
Route::get('/one/two/three/four/five', 'ErrorController@index'); 
Route::get('/one/two/three/four/five/six', 'ErrorController@index'); 
Route::get('/one/two/three/four/five/six/seven', 'ErrorController@index'); 

【问题讨论】:

【参考方案1】:

不错,但不是很实用。您想要的是在您的 url 中将所有参数作为查询字符串传递。即

/any?id=1&name=joe

并像这样定义你的路线

Route::get('/any',function()
    return Request::all();
)//

输出

"id":"1","name":"joe"

【讨论】:

以上是关于在 laravel 5 中通配符到错误控制器的路由的主要内容,如果未能解决你的问题,请参考以下文章