本文介绍了Laravel在之间或之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个Laravel查询.我在名为"shareable"的列上使用whereBetween
和orWhereBetween
以及where
语句,该列应该返回一行.但是此查询未考虑where
条件.仅花费了whereBetween
和orWhereBetween
.可能是什么原因.
I have written a Laravel query. I am using whereBetween
and orWhereBetween
along with a where
statement on a column named 'shareable', which should return one row.
But this query does not take where
condition into consideration. It took only whereBetween
and orWhereBetween
. What can be the reason.
我的查询
$childs = Program::whereIn('id', $programs_by_date)
->where('shareable', '=','1')
->wherebetween('starting_date', [$new_start_date,$new_end_date])
->orwherebetween('ending_date', [$new_start_date,$new_end_date])
->orderBy('starting_date')
->get();
->where('shareable', '=','1')
返回0行.可能是什么原因.
->where('shareable', '=','1')
return 0 rows. What can be the reason.
shareable
类型为枚举
推荐答案
尝试一下:
$childs = Program::whereIn('id', $programs_by_date)
->where('shareable', '=','1')
->where(function($query) use ($new_start_date, $new_end_date){
$query->wherebetween('starting_date', [$new_start_date,$new_end_date])
->orwherebetween('ending_date', [$new_start_date,$new_end_date])
})
->orderBy('starting_date')
->get();
希望这会起作用.
这篇关于Laravel在之间或之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!