如果输入全部包含在 Laravel 中,则停用过滤
Deactivate filtering if inputs comes with all in Laravel
我正在尝试过滤结果
$students = \App\User::leftJoin('exam_places', 'exam_places.exam_place_no', '=', 'users.exam_place_id')
->select(['exam_places.*',
'users.*',
])
->where('exam_places.id',$input['examplace'])
->where('users.paymenet_method',$input['payment'])
->where('users.payStatus',$input['status'])->get();
例如,我的输入是这样的(全部,1,2,3,4,5)
对于付款方式(全部、1、2、3、4、..)
对于工资状态(0,1)
我所有的过滤方法都有效,但是如果用户选择全部作为我的
$input[examplace]= all
where 语句查找
where('exam_places.id','all')
但是,如果全部选中,我想禁用此语句。
我尝试添加
if($input[examplace] !=='all') {
->where('exam_places.id',$input['examplace'])
}
它给了我错误。
编辑:让我简要解释一下我试过的代码
$students = \App\User::leftJoin('exam_places', 'exam_places.exam_place_no', '=', 'users.exam_place_id')
->select(['exam_places.*',
'users.*',
])
if($input['examplace'] !== 'all){
->where('exam_places.id',$input['examplace'])
}
->where('users.paymenet_method',$input['payment'])
->where('users.payStatus',$input['status'])->get();
它给我下面的错误
所以问题是,如果输入为 all,我该如何停用我的 if 语句?
您正试图在链接中添加逻辑语句,如果不将它们分开就无法做到这一点
尝试按顺序添加语句:
$stmt = \App\User::leftJoin('exam_places', 'exam_places.exam_place_no', '=', 'users.exam_place_id')
->select(['exam_places.*','users.*',]); //break here
if($input['examplace'] !== 'all'){
$stmt->where('exam_places.id',$input['examplace']);
}
$stmt->where('users.paymenet_method',$input['payment'])
->where('users.payStatus',$input['status']);
$students = $stmt->get();
我正在尝试过滤结果
$students = \App\User::leftJoin('exam_places', 'exam_places.exam_place_no', '=', 'users.exam_place_id')
->select(['exam_places.*',
'users.*',
])
->where('exam_places.id',$input['examplace'])
->where('users.paymenet_method',$input['payment'])
->where('users.payStatus',$input['status'])->get();
例如,我的输入是这样的(全部,1,2,3,4,5) 对于付款方式(全部、1、2、3、4、..) 对于工资状态(0,1)
我所有的过滤方法都有效,但是如果用户选择全部作为我的
$input[examplace]= all
where 语句查找
where('exam_places.id','all')
但是,如果全部选中,我想禁用此语句。
我尝试添加
if($input[examplace] !=='all') {
->where('exam_places.id',$input['examplace'])
}
它给了我错误。
编辑:让我简要解释一下我试过的代码
$students = \App\User::leftJoin('exam_places', 'exam_places.exam_place_no', '=', 'users.exam_place_id')
->select(['exam_places.*',
'users.*',
])
if($input['examplace'] !== 'all){
->where('exam_places.id',$input['examplace'])
}
->where('users.paymenet_method',$input['payment'])
->where('users.payStatus',$input['status'])->get();
它给我下面的错误
所以问题是,如果输入为 all,我该如何停用我的 if 语句?
您正试图在链接中添加逻辑语句,如果不将它们分开就无法做到这一点 尝试按顺序添加语句:
$stmt = \App\User::leftJoin('exam_places', 'exam_places.exam_place_no', '=', 'users.exam_place_id')
->select(['exam_places.*','users.*',]); //break here
if($input['examplace'] !== 'all'){
$stmt->where('exam_places.id',$input['examplace']);
}
$stmt->where('users.paymenet_method',$input['payment'])
->where('users.payStatus',$input['status']);
$students = $stmt->get();