如果设施出现请求,则需要加入,否则不需要使用 library_members 或居民表等设施加入查询。
public function add(Request $request)
{
$facility = $request->get('facility');
$data['student'] = Student::select('students.id','students.reg_no','students.reg_date', 'students.first_name', 'students.middle_name', 'students.last_name','students.faculty', 'students.semester','students.status')
->join('library_members as l','l.reg_no','=','students.reg_no')
->join('residents as r','r.reg_no','=','students.reg_no')
->get();
}
答案 0 :(得分:1)
public function add(Request $request)
{
if($request->has('facility')){
$facility = $request->get('facility');
$data['student'] = Student::select(
'students.id','students.reg_no',
'students.reg_date', 'students.first_name',
'students.middle_name', 'students.last_name',
'students.faculty', 'students.semester','students.status'
)
->join('library_members as l','l.reg_no','=','students.reg_no')
->join('residents as r','r.reg_no','=','students.reg_no')
->get();
}else{
$data['student'] = Student::select('fields')->get();
}
}