通配符 laravel 5 中错误控制器的路由
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"}
我想在 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"}