Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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 .

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

emchooo emchooo Joined 3 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.