php - Laravel/Eloquent WHERE NOT SUBQUERY

标签 php mysql laravel-5 eloquent

我无法设置这样的负面条件:

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

最佳答案

你可以玩逻辑

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

关于php - Laravel/Eloquent WHERE NOT SUBQUERY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43215081/

相关文章:

php - 通过单击链接提交表单,而不使用提交按钮

mysql - 哪个是为了更快地获取结果?

php - 匹配 MySQL JSON 列的全部内容

php - 在 laravel 5 中写入自定义日志以及 laravel.log

php - 使用 Laravel 解析电子邮件地址

php - 文件权限;我的 www 文件夹内容应该归 www 数据所有吗?

php - 如果还有 css

php - 从购物篮中删除商品 Opencart 自定义按钮

php - 如何将PHP中数据库的多列求和为一个结果?那可能吗?

php - 如何在 Laravel 5 中检索 View 名称?