You would want to group the wheres for the college or university. You can try something like this:
$exams = Exam::where('status', 1);
if ($request->has('universities', 'colleges')) {
$exams->where(function ($q) use ($request) {
if ($request->input('universities')) {
$q->orWhereIn('university_id', (array) $request->input('universities'));
}
if ($request->input('colleges')) {
$q->orWhereIn('college_id', (array) $request->input('colleges'));
}
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…