0
I am developing a filter system in which the user may or may not fill in some form fields. In the controller, I’m trying to do a Where as follows:
//demais filtros
$imoveis = Imovel::where([
'finalidade' => $request['finalidade'],
'tipo_id' => $request['tipo_id'],
'cidade_id' => $request['cidade_id'],
'bairro' => $request['bairro'],
'area' => $request['area'],
'quartos' => $request['quartos'],
'banheiros' => $request['banheiros'],
'suites' => $request['suites'],
'garagens' => $request['garagens'],
])->get();
However, I want to somehow ignore the values that were not filled in by the user, and that come as null in the request.
An example of dd($request->all()) is:
array:14 [ "_token" => "Nbfiyyw7xqfqr2j858zq7stliaqoyb0mzo1ckknz" "id" => null "name" => null "purpose" => "1" "id type" => null "city_id" => null "neighborhood" => null "area" => null "rooms" => null "suites" => null "toilets" => null "garages" => null "valueMinimo" => null "valueMaximo" => null ]
Thank you for the reply! You attended well to what I needed!
– Gabriel Augusto