$location = $details['location'];
$specializationAreasName = $details['specialization_areas'];
if($details['location'] == 'all'){
$location = '';
}
if($specializationAreasName == 'all'){
$specializationAreas = '1 = 1';
}
else{
$specializationAreas = "'specialization_areas','like', '%'".$specializationAreasName."'%'";
}
$result = Lawyers :: with('SkillsMappedToLawyer')
->where('location',$location)
->where($specializationAreas)
->take(10)->skip($skip)
->get();
请找到我的代码如果位置==所有我想要搜索全部,否则我需要搜索动态的标准。 有人可以帮我解决这个问题吗?
答案 0 :(得分:2)
试试这个:
$location = $details['location'];
$specializationAreasName = $details['specialization_areas'];
$query = Lawyers :: with('SkillsMappedToLawyer');
if($details['location'] != 'all'){
$query = $query->where('location', $location);
}
if($specializationAreasName != 'all'){
$query = $query->where('specialization_areas', 'LIKE', '%'.$specializationAreasName.'%');
}
$result = $query
->take(10)->skip($skip)
->get();