问题
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