1
My goal in the code is:
- Create a filter option for the customer, where he will have the options to filter the product by: COLOR, GROUP, FEATURE AND MEASURES.
My problem is:
- Create the query that accepts array’s and accepts when one of the filter options is not selected. For example: I only want to filter by color, but not by other options.
Code I have so far.
$produtos = DB::table('products')
->join('cores_produto','cores_produto.produto_id','products.id')
->join('grupos_produto','grupos_produto.produto_id','products.id')
->whereIn('cores_produto.cor_id', $c )
->whereIn('grupos_produto.grupo_id', $g)
->groupBy('products.id')->orderBy('products.id')
->select('*')
->toSql();
Return of sql query by selecting only the color option.
select * from `products` inner join `cores_produto` on `cores_produto`.`produto_id` = `products`.`id` inner join `grupos_produto` on `grupos_produto`.`produto_id` = `products`.`id` where `cores_produto`.`cor_id` in (?) and 0 = 1 group by `products`.`id` order by `products`.`id` asc
Boy I couldn’t understand your question, it has to explain otherwise or more clearly ?
– Bulfaitelo
For example, I go in the filter and I want to know all the products that have the color "Blue and Yellow", but I do not select anything in the group, it returns me an empty query, because instead of it does not play in the query what is null it plays the value 'and 0 = 1', here it comes empty.
– adrib
where would enter this null value ? I’m still not sure which is your problem.
– Bulfaitelo
Your question is not very clear
– novic
@Virgilionovic sorry I’m not being very clear staff. I edited the post for a better understanding.
– adrib