Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pthai-it-dev's avatar

Define route in Laravel with multi parameters for multi conditions in query

i have a table user in database and i want to define a route to query users in table with different "where" conditions passed by url. Example i want to query users with only 2 conditions B and C but sometimes i want to query users with 3 or more conditions like B, C and D .... How should i define a route or some routes to solve this problem. Thank you for reading!

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

Using query parameters. What you are describing is still an index action; so I would suggest you filter the Eloquent/Database query using query parameters:

Route::get('users', [UserController::class, 'index']);

You would visit a URL like https://your-domain.tld/users?active=1&is_customer=0

How you handle the query filtering in the Controller is up to you; this video tutorial describes creating Filter classes so that you have some control over the query parameters than can be handled

1 like

Please or to participate in this conversation.