[英]Laravel - PHP/MySQL date range filter against date range in database
我正在使用Laravel开发应用程序,并且试图从数据库中过滤记录。 这是标准:
在数据库中,我有2个日期列[excluded_period_start]
和[excluded_period_end]
。 两列都具有日期数据类型。
现在,我在[start_date]
和[end_date]
表单中有2个字段。
我想获取除数据库中存储的期间以外的所有记录。 我使用的代码是:
$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])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.