我正在使用 Laravel 开发一个应用程序,我正在尝试从数据库中过滤记录。以下是标准:
在数据库中,我有 2 个日期列[excluded_period_start]
和[excluded_period_end]
. 两列都有日期数据类型。
现在我的表单中有 2 个字段[start_date]
和[end_date]
.
我想获取除数据库中存储的时间段之外的所有记录。我正在使用的代码是:
$hotels = Hotel::whereHas('location' , function($query) use($searchOptions){
if(trim($searchOptions['location']) != ''){
$query->where('location_title', $searchOptions['location']);
}
})
->where('excluded_period_start', '<', $start)
->where('excluded_period_end', '>', $end)
->where('active', 1)
->take(10)
->paginate(10);
但是,这只给我的结果介于存储在我的数据库中的范围之间,但我想要该范围之外的结果。
我尝试过很多类似的事情,->whereBetween()
但没有一个奏效。
任何帮助,将不胜感激。
您最初的 exclude_period 不能介于开始和结束之间:
->whereNotBetween('excluded_period_start', [$start, $end])
->whereNotBetween('excluded_period_end', [$start, $end])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句