My approach :
$name = Input::get('name', null);
$city = Input::get('city', null);
$query = Worker::select('fields', 'you', 'need');
// Add name filter
$query = is_null($name) ? $query : $query->whereName($name);
// Add city filter
$query = is_null($city) ? $query : $query->whereCity($city);
$workers = $query->get();
is_null
also saves from empty string ''
I would consider iterating through Input::all()
as not very wise .
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community