2017-04-04 121 views
2

遇到问题我真的要设置像这样的消极条件:Laravel /雄辩WHERE NOT子查询

WHERE NOT("last_day" "<=" $first_day OR "first_day" "<=" $last_day) 

我的查询生成器看起来像这样ATM:

$query = $query->where(function ($query) use ($first_day, $last_day) { 
    $query->where('last_day', '<=', $first_day); 
    $query->orWhere('first_day', '<=', $last_day); 
}); 

我想它是因此:

$query = $query->whereNot(function ($query) use ($first_day, $last_day) { 
    $query->where('last_day', '<=', $first_day); 
    $query->orWhere('first_day', '<=', $last_day); 
}); 

回顾:我想在一个负的WHERE条件内的OR语句。我怎样才能做到这一点?

来源:http://baodad.blogspot.nl/2014/06/date-range-overlap.html

+0

我不认为你的操作数是正确的。你究竟在检查什么? – aynber

+0

他们确实没有,我会编辑,并完全指定 – MrMedicine

+0

基本上我正在尝试做的是:http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap – MrMedicine

回答

0

您可以用逻辑

$query = $query->where(function ($query) use ($first_day, $last_day) { 
    $query->where('last_day', '>', $first_day); 
    $query->where('first_day', '>', $last_day); 
}); 
+0

我不要认为逻辑是一样的,它不符合:“艾伦的区间代数”:https://en.wikipedia.org/wiki/Allen%27s_interval_algebra – MrMedicine

+0

更改:$ query->其中('first_day',' >',$ last_day);到$ query-> where('first_day','<',$ last_day);和它的正确,请参阅:http://stackoverflow.com/questions/43233652/eloquent-mysql-statement-where-nota-or-b – MrMedicine