通配符一个到错误控制器的路由


Wildcard a route to error controller in laravel 5

我想在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'); 

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

/any?id=1&name=joe

并像这样定义你的路由

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

输出
{"id":"1","name":"joe"}