路线Laravel的网址

问题描述 投票:0回答:3

我想使用网址:http:localhost:8000/api/students/?key=value

我的API设置如下:

Route::get('students/{key},'Controller@method')

但我的网址是:http:localhost:8000/api/students/value有人可以帮我吗?

php laravel
3个回答
1
投票

如果您想将密钥作为$ _GET参数传递,您希望将路由更改为:

Route::get('students/,'Controller@method')

这样你就可以使用http:localhost:8000/api/students/并传递你想要的任何参数


0
投票

改变你的路线:

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;

}

0
投票
Route::prefix('api')->group(function () {
    Route::get('students/{key}','Controller@method');
    // here come api-prefixed routes
});

https://laravel.com/docs/5.6/routing#route-group-prefixes

© www.soinside.com 2019 - 2024. All rights reserved.