the issue is that if the user does not choose some values in the searchform, (because he may want broad search) the WHERE clauses will
fail. For example, if he does not choose construction year for the house, then, since all the houses have a construction year, nothing will be shown.
or if he does not choose a price limit for the house, then, paradoxically no results will be shown because no houses cost less than nothing.
I solved that issue in codeigniter where I could code IF clauses within the sql query, but here in Laravel I just dont know how to go about it. I have tried many
syntaxes, like
->if($priceto != "")
{
->where('price', '<',$priceto)
}
but all fail.
So here are some input values from the form. Think that some may be unfilled
$country = Input::get('country');
$region = Input::get('regions');
$town = Input::get('town');
$transaction = Input::get('transaction');
$pricefrom = Input::get('pricefrom');
$priceto = Input::get('priceto');
$builtyear = Input::get('builtyear');
}
$users = DB::table('users')
->join('properties', 'users.id', '=', 'properties.id_user_fk')
->select('users.email', 'properties.country', 'properties.region', 'properties.town', 'properties.price', properties.rooms','properties.m2','properties.swimming',
'properties.garden','properties.garage','properties.builtyear','properties.pic1',
'properties.pic2')
here below is where the problems start, because of what mentioned, what if the variables $priceto or $builtyear have nothing in them, nothing is shown
->where('country', '=', $country)
->where('region', '=', $region)
->where('town', '=', $town)
->where('transaction', '=', $transaction)
->where('price', '<', $priceto)
etc etc
I also thought of checking what variables have a value and push them into an array before starting the sql query, but the problem is then reading the array from the sql query.