9

I am trying to know how to add query parameters to routes in Lumen

this is an example of a route I created

$app->get('/product/{apikey}','ProductController@getProduct');

This works when I use

http://api.lumenbased.com/product/10920918

but I would like to use it like this

http://api.lumenbased.com/product/?apikey=10920918

I tried this

$app->get('/product/?apikey={apikey}','ProductController@getProduct');

But this gives me MethodNotAllowedHttpException

I would like to know how to write routes with query parameters in Lumen ?

Rishabh
  • 3,752
  • 4
  • 47
  • 74

1 Answers1

11

Just do:

$app->get('/product','ProductController@getProduct');

and use:

$request->get('apikey')

in the ProductController@getProduct function.

(That said, validating an API key is better done via middleware...)

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Thanks for the answer and the recommendation I implemented a middleware using jwt $app->get('/product',['middleware' => 'jwt.auth','uses' => 'ProductController@getProduct']); – Rishabh Aug 08 '16 at 11:08