Welcome to Trishul API Questions and Answers. Help and learn how to use it efficiently.
0 like 0 dislike
8 views
in Request by (570 points)
Hi developers, sometimes you have to apply filters based on the query params.

For example if url has user_id then you want to filter the user data by user_id and if url has username in query params then you will filter the data by username

Url example: https://example.com/users?user_id=54

https://example.com/users?username=shyam

In this situation, your API endpoint needs query params. How will you get these query params?

1 Answer

0 like 0 dislike
by (570 points)
 
Best answer
Welcome Developers,

In this situation, a class QueryParam.php is there which consists many useful methods for getting and checking the query params.

You can get the instance of query-params from request object.

$user_id = $request->query_params()->get('user_id);

If user_id query param doesn't exist in url it will return null.

Same way you can get the query params from any url.

Read this:- https://trishulapi.com/docs/v1x/Http/Request.php
Welcome to TrishulAPI Q&A, where you can ask questions and receive answers from other members of the community.
...