Laravel参数分组(和/或其中)
我将Laravel升级到了第7版,当我进行这样的查询时:Laravel参数分组(和/或其中),laravel,Laravel,我将Laravel升级到了第7版,当我进行这样的查询时: $users = User::where('name', '=', 'John') ->where(function ($query) { $query->where('votes', '>', 100) ->orWhereNull('title'); }) ->get()
$users = User::where('name', '=', 'John')
->where(function ($query) {
$query->where('votes', '>', 100)
->orWhereNull('title');
})
->get();
它无法按预期工作,我遇到了此错误[SQL Server]必须指定要从中选择的表
因为SQL应该是这样的:
select * from users where name = 'John' and (votes > 100 or title is null)
select * from users where name = 'John' and (select * votes > 100 or title is null) is null
但当我调试返回的查询时,它显示如下:
select * from users where name = 'John' and (votes > 100 or title is null)
select * from users where name = 'John' and (select * votes > 100 or title is null) is null
上面的查询只是我复杂查询的一个例子,我的所有项目中都有很多类似的查询,因此我不需要替换,我只需要知道如何修复它,因为它在升级之前工作正常。例如,您可以使用
whereRaw
作为替代方法
$users = Table::whereRaw(" name=? AND (votes=? OR title=?)", array(?,?,?))