Hi, everyone, currently I'm using if condition on request to check for specific query param and filter it in eloquent query builder. I think you can imagine my problem! Is there a simple way to handle all of this?
You can use "only" to select only the data you want from request
For example:
request()->only('brand', 'category', 'size')
will return array with the parameter from the requested set. For example, if only brand presented in request - you'll have array with 1 element only, if brand and size - result will have array with 2 elements
@gthell Well, no. If you watch the video I gave you the link to, you could create a class that add clauses to your query builder instance based on items in the query string.
It means you then have a class solely responsible for filtering and sorting, and your models don’t get full of scopes that are inspecting HTTP requests (which they shouldn’t do).