A simple where chain for each field that you need to execute to search:
// AND $results = SomeModel::where('location', $location)->where('blood_group', $bloodGroup)->get(); // OR $results = SomeModel::where('location', $location)->orWhere('blood_group', $bloodGroup)->get();
You can simplify the work thanks to the areas:
// SomeModel class public function scopeSearchLocation($query, $location) { if ($location) $query->where('location', $location); } public function scopeSearchBloodGroup($query, $bloodGroup) { if ($bloodGroup) $query->where('blood_group', $bloodGroup); } // then SomeModel::searchBloodGroup($bloodGroup)->searchLocation($location)->get();
Just a reasonable example, customize it to your needs.
source share