直接上代码
if (!empty($all['stu_name'])) {
$where[] = ['student.stu_name', 'like', '%' . $all['stu_name'] . '%'];
}
#这个就是依据classes_name查询组合数据
if (!empty($all['classes_name'])) {
$where[] = ['cla.classes_name', 'like', '%' . $all['classes_name'] . '%'];
}
if (!empty($all['phone'])) {
$where[] = ['student.phone', 'like', '%' . $all['phone'] . '%'];
}
if (!empty($all['sch_id'])) {
$where[] = ['student.sch_id', $all['sch_id']];
}
if (!empty($all['class'])) {
$where[] = ['student.class', $all['class']];
}
$where[] = ['student.status', 1];
$total = Student::where($where)->count();
// 获取所有学生的信息
$stuAll = Student::where($where)
->select('student.id as stu_id', 'stu_name', 'phone', 'sch_name', 'classes_name', 'points','class')
->leftJoin('classes as cla', 'cla.id', 'class')
->leftJoin('school as sch', 'sch.id', 'sch_id')
->offset($offset)
->limit($pagesize)->get();