我有以下查询链接的地方:
->where('start_timestamp', '<=', $activity->timestamp)
->where('end_timestamp', '>=', $activity->timestamp)
->where('minimum_activity_distance', '<=', $activity->distance)
->where('maximum_activity_distance', '>=', $activity->distance)
->where('minimum_activity_duration', '<=', $activity->duration)
->where('maximum_activity_duration', '>=', $activity->duration)
->where('minimum_activity_timestamp_time', '<=', $activity->timestamp->format('H:i:s'))
->where('maximum_activity_timestamp_time', '>=', $activity->timestamp->format('H:i:s'));
但是,列也可能为NULL。如果是这样,我不希望条件适用。
所以如果minimum_activity_distance
为NULL
我想跳过/忽略
->where('minimum_activity_distance', '<=', $activity->distance)
答案 0 :(得分:1)
您可以将where
与closure用于此
->where(function ($q) use ($activity) {
$q->where('minimum_activity_distance', '<=', $activity->distance)
->orWhereNull('minimum_activity_distance');
})