@redlik Use conditional clauses, like when for example?
May 11, 2021
3
Level 2
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.
Level 27
Please or to participate in this conversation.