0

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?

1
  • What have you tried so far? Any code you can share with us to help you? Commented Mar 6, 2018 at 10:46

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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;

}

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.