Back

AJAX Filters on laravel


Andrew Alexeew posted 5 months ago

How develop that http://joxi.ru/5mdBeqJTkzDNgA filters on laravel. I am make ajax request and in controller getting data via where(function ($query) use ($filter) { ... } exemple:

            $usersFiltersOther = $users->where(function ($query) use ($filter) {
                foreach ($filter as $item) {
                    if ($item[0] == 'Age') {
                        foreach ($item[1] as $age) {
                            $range = explode('-', $age);

                            $from = (int)$range[0];
                            $to = (int)$range[1];

                            $query->orWhereBetween('age', array($from, $to));
                        }
                    }

                    $query->orWhereIn($item[0], $item[1]);

                }
            });

But I myself do not like this approach

How do I improve the code? How to make it more convenient and readable? make it not look like noodles


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us