Laravel / Eloquent WHERE NOT SUBQUERY

混江龙づ霸主 提交于 2020-01-04 01:31:12

问题


I`m having trouble to setup a negative condition like such:

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

My query builder looks like this atm:

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

I would like it to be as such :

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

To recap: I want an OR statement inside a negative WHERE condition. How can I accomplish this?

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


回答1:


You can play with the logic

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



回答2:


Went with reverting constraints according to answer found here: Eloquent MYSQL statement : WHERE NOT(A OR B)

$query = $query->where('last_day', '>', $first_day)->where('first_day', '>', $last_day);


来源:https://stackoverflow.com/questions/43215081/laravel-eloquent-where-not-subquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!