Is there a possibility to create a routing based on query parameters? For example, an external system is calling the following route:
https://example.com/api?Action=GetOrders&Key=abf24b12c3b2a4e4b4dabbdd
Dependent on the value of Action
, I would like to call different controller methods.
How can I do this while maintaining the functionality of the Service Container and Dependency Injection?
I tried like this, but it did not work:
Route::get('api?Action={Action}', function (Request $request, string $action) {
dd($action);
});
Thanks!
3
Answers
Try this
Laravel doesn’t handle query parameters (?) directly in its routes.
In route
Controller
you should use Controller that can simplify.
If you want to use laravel routing method use something like
If you like to do with https://example.com/api?Action=GetOrders&Key=abf24b12c3b2a4e4b4dabbdd use $_GET[‘action’] or $request->action; with if in your Controller