Reputation: 1
i want to use url like: http:localhost:8000/api/students/?key=value
.
My API is set up as follows:
Route::get('students/{key},'Controller@method')
but my url is: http:localhost:8000/api/students/value
Could anyone help me please?
Upvotes: 0
Views: 55
Reputation: 304
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
Upvotes: 0
Reputation: 3414
If you want to pass the key as a $_GET param you want to change your route to just be:
Route::get('students/,'Controller@method')
That way you can use http:localhost:8000/api/students/
and pass any parameters you want
Upvotes: 1
Reputation: 13669
Change Your Route :
Route::get('students,'Controller@method')
in Your Controller use
$request->input('key') or $request->query('key')
public function method(Request $request){
$value = $request->query('key');
$value2 =$request->input('key');
echo $value;
echo $value2;
}
Upvotes: 0