7,并让用户使用DB类来过滤数据库中的结果。
$profiles = DB::table('profiles')->where('status_id', '=', 1)
->when($genderCheckbox, function($query) use ($vacature){
return $query->where('gender_id', '=', $vacature->gender_id);
})
->when($salaryCheckbox, function($query) use ($vacature){
return $query->where('min_salary', '<=', $vacature->salary)->where('max_salary', '>=', $vacature->salary);
})
->when($ageCheckbox, function ($query) use ($vacature){
return $query->whereDate('birthday', '<', Carbon::today()->subYear($vacature->min_age))->whereDate('birthday', '>', Carbon::today()->subYear($vacature->max_age));
})
->when($educationCheckbox, function ($query) use ($viableEducationArray){
return $query->whereIn('done_education_id', $viableEducationArray);
})
->when($timeCheckbox, function ($query) use ($vacature){
return $query->where('shift_id', '=', $vacature->shift_id)->orWhere('shift_id', '=', null);
})
->when($licenseCheckbox, function ($query) use ($vacature){
if ($vacature->license_type_id == 1){
return $query->where('license_type_id', '>=', $vacature->license_type_id);
}elseif ($vacature->license_type_id == 2){
return $query->where('license_type_id', 2)->orWhere('license_type_id', 4);
}elseif ($vacature->license_type_id == 3){
return $query->where('license_type_id', 3)->orWhere('license_type_id', 4);
}elseif ($vacature->license_type_id == 4){
return $query->where('license_type_id', 4);
}
})
->when($districtCheckbox, function ($query) use ($vacature){
return $query->where('district_id', $vacature->district_id);
})
->when($residenceCheckbox, function ($query) use ($vacature){
return $query->where('residence_id', $vacature->residence_id);
})
->get();
到目前为止,它一直工作良好。我已经设置了3个表,用户,天数和工作量。用户可以使用很多天。招聘还可能要求用户在某天到场。此时,我将创建两个数据透视表。问题是,我如何只让所选天数满足求职者条件的用户。
预先感谢