S
S
SpinPr2018-05-21 12:04:51
Laravel
SpinPr, 2018-05-21 12:04:51

How to make a dynamic product filter in Laravel?

There are related tables Goods and Sizes, Brands, Parameters.
The filtering process itself is implemented, i.e. product selection:
Controller:

$goods = Good::select('id', 'name', 'brand_id', 'price');
        $goods = (new MyGoodsFilter($goods, $request))->apply();
        $goods = $goods->get();

Filter snippet:
// Фильтрация по размерам
        $this->builder->whereHas('sizeid', function ($query) use ($value) {
            $query->Where(function ($query) use ($value) {
                $sizes = explode(",", $value);
                foreach ($sizes as $size) {
                    $query->orwhere('size_id', '=', $size);
                }
            });

But in each section there will already be extra filter elements (which are not in the table of the corresponding products). Each time you select a filter element, new non-working elements will appear.
What is the best way to leave only work items in the filter on each selection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vilintritenmert, 2018-05-31
@Vilintritenmert

Display to the user a list of parameters that are in the table of the corresponding products.
Make a request based on $request (we filter which parameters came from them)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question