[英]Url in Route Laravel
i want to use url like: http:localhost:8000/api/students/?key=value
. 我想使用以下网址: http:localhost:8000/api/students/?key=value
。
My API is set up as follows: 我的API设置如下:
Route::get('students/{key},'Controller@method')
but my url is: http:localhost:8000/api/students/value
Could anyone help me please? 但我的网址是: http:localhost:8000/api/students/value
有人可以帮我吗?
If you want to pass the key as a $_GET param you want to change your route to just be: 如果要将密钥作为$ _GET参数传递,则要将路径更改为:
Route::get('students/,'Controller@method')
That way you can use http:localhost:8000/api/students/
and pass any parameters you want 这样,您可以使用http:localhost:8000/api/students/
并传递所需的任何参数
Change Your Route : 更改路线:
Route::get('students,'Controller@method')
in Your Controller use 在您的控制器中使用
$request->input('key') or $request->query('key') $ 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
});
https://laravel.com/docs/5.6/routing#route-group-prefixes https://laravel.com/docs/5.6/routing#route-group-prefixes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.