我想使用网址:http:localhost:8000/api/students/?key=value
。
我的API设置如下:
Route::get('students/{key},'Controller@method')
但我的网址是:http:localhost:8000/api/students/value
有人可以帮我吗?
如果您想将密钥作为$ _GET参数传递,您希望将路由更改为:
Route::get('students/,'Controller@method')
这样你就可以使用http:localhost:8000/api/students/
并传递你想要的任何参数
改变你的路线:
Route::get('students,'Controller@method')
在您的控制器使用中
$ request-> input('key')或$ request-> query('key')
public function method(Request $request){
$value = $request->query('key');
$value2 =$request->input('key');
echo $value;
echo $value2;
}
Route::prefix('api')->group(function () {
Route::get('students/{key}','Controller@method');
// here come api-prefixed routes
});