in_array
中使用的函数
when
因为0(zero)在默认情况下表示(false),所以请尝试在when方法中使用内部函数
2
或任何数字,但不是
0,1 and null
$status = Input::has('status') ? Input::get('status') : 2;
$events = DB::table('events')->select('events.*')
->when(in_array($status,[0,1]), function ($query) use ($status) {
return $query->where("events.status",$status);
})->get();
function checkStatus($status,$array) {
if(isset($status)) {
return in_array($status,$array);
}
return false;
}
$events = DB::table('events')->select('events.*')
->when(checkStatus($status,[0,1]), function ($query) use ($status) {
return $query->where("events.status",$status);
})->get();