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

redlik's avatar

Selected or all in eloquent query

Hi, I'm looking for a best way to make an eloquent query where the result is optionally filtered by a dropdown. What I mean is if something is selected then query with just that option, if nothing is selected get all items. My model is a sports club member, but it has relationship with other models - membership, grade, qualification etc. and these will be used as filters also.

Some filters will act directly on model's columns but there will be few dropdown or checkboxes that query through relationships.

All filters are passed by $request object into the controller.

0 likes
3 replies
redlik's avatar

Thnx for the link. That was my initial idea but just wanted to double check with the experts if there was a better way.

1 like

Please or to participate in this conversation.