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