I'm developing a filter system in which the user can or may not fill some fields of a form. In the controller, I'm trying to do a where in the following way:
//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 ignore somehow the values that were not filled by the user, and which come as null in the request.
An example of dd ($ request-> all ()) is:
array: 14 [▼ "_token" = > & Quot; "id" = > null "name" = > null "purpose" = > "1" "type_id" = > null "ciudad_id" = > null "neighborhood" = > null "area" = > null "rooms" = > null "suites" = > null "bathrooms" = > null "garages" = > null "minimum value" = > null "max value" = > null ]