Filter's query returns collection but table stays empty
Hi everyone, I am experiencing strange behaviour from one of my filters.
I have created a mix-max field, where I basically go and filter my records by minimum and maximum price. The query works through a normal when, with 2 different options: if a minimum price is entered and if a maximum price is entered.
This way, when the maximum price was deleted from the input, the table returned nothing.
So I thought of creating a third option: i.e. if the maximum price is null it returns all records with price <= the maximum possible price (obtained through a db query), but nothing has changed.
I've done some dumps and actually the code enters the when and, doing a dump of $query, the where exists; doing a dump of $query->get() I get the records I expect (i.e. all of them); the problem is that anyway the table remains empty.
Solution:Jump to solution
I solved it by simplifying the callback within query, like this:
```
->query(function (Builder $query, array $data): Builder {
if($data['pricing']['max'] > 0){
$query = $query->where('price', '<=', $data['pricing']['max']);...
2 Replies
Here is my code:
Am I doing something wrong? Do you have any other ways to solve this? All I would need is for the table to display all the records once the input has been emptied of the maximum price.
Solution
I solved it by simplifying the callback within query, like this: