【发布时间】:2019-09-30 20:24:47
【问题描述】:
尝试使用和/或 where 语句,就好像它们嵌套在括号中一样。 示例:
Select * from myTable
where
(id > 78 or name is not null)
and term_date >= NOW())
尝试让这些复杂的 where 语句在 Laravel 集合中使用,如下所示:
$query = myTableModel::where(['id', '>', 78])
->orWhereNotNull('name')
->where('term_date', '>=', date('Y-m-d'))
但是这种类型的查询会返回一个这样的地方
where
(id > 78 or
name is not null and
term_date >= Now())
或任何其他奇怪的 where 组合,而不是设置嵌套括号。
有没有办法使用 laravel Collections 解决此类问题?
【问题讨论】:
标签: php mysql laravel collections