[英]Laravel Eloquent having trouble comparing dates in query
I have this query for Eloquent and for some reason it seems to be ignoring my last statement about only return dates that equal or greater then that date given. 我对Eloquent有此查询,由于某种原因,它似乎忽略了我的最后一条语句,即仅返回等于或大于给定日期的返回日期。
$searchCriteriaArray
is the array the key words I am search based on(this works) $searchCriteriaArray
是我要搜索的关键词的数组(这有效)
$searchDate is the
date I am filtering on (this does not work) $searchDate is the
我过滤$searchDate is the
日期(这不起作用)
here is my query 这是我的查询
$pool =User::select('id', 'email', 'updated_at', 'phone_number', 'headline','summary')
->where(function ($query) use ($searchCriteriaArray){
for($i =0; $i < count($searchCriteriaArray); $i++){
$query->orwhere('headline', 'like', '%' . $searchCriteriaArray[$i] . '%' );
}
})->orWhere(function ($query) use ($searchCriteriaArray){
for($i =0; $i < count($searchCriteriaArray); $i++){
$query->orwhere('summary', 'like', '%' . $searchCriteriaArray[$i] . '%' );
}
})->where('updated_at', '>= ',$searchDate)
->orderBy('updated_at', 'desc')
->paginate(50);
I have looked as some other posts, including Laravel Eloquent compare date from datetime field . 我看过其他文章,包括Laravel Eloquent从datetime字段比较日期 。 However this has not solved my problem.
但是,这并没有解决我的问题。 Why is Eloquent ignoring my last where statement and how do I fix this?
为什么Eloquent忽略了我的最后一个where语句,我该如何解决?
Someone posted the answer and then deleted it. 有人发布了答案,然后将其删除。 I needed to add this line
我需要添加这一行
->where(function ($query) use ($searchDate){
$query->orwhere('updated_at', '>=', $searchDate);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.