【问题标题】:or where query on model或查询模型
【发布时间】:2017-01-06 15:14:11
【问题描述】:

我试图弄清楚为什么会发生某些事情。

当一个模型被创建时,它被赋予一个状态参数。最初的状态是等待信息,但很快就变成了等待接受。只有当模型的状态已通过这两个阶段时,我才会尝试在我的页面上显示模型。目前我有以下内容

$projects = Project::with('client')->where('status', '!=', 'Awaiting Information')->orWhere('status', '!=', 'Awaiting Acceptance')->get();

但是,由于某种原因,这会返回一个状态为等待信息的项目。如果我删除 orWhere 部分,则不会按预期显示任何项目。看来 orWhere 正在抛出查询。我希望退回所有没有这些状态的项目。

我的条款中是否遗漏了什么?

谢谢

【问题讨论】:

标签: laravel laravel-5.2


【解决方案1】:

我建议您使用 whereNotIn 方法进行查询:

$projects = Project::with('client')->whereNotIn('status', ['Awaiting Information', 'Awaiting Acceptance'])->get();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 2015-07-13
    相关资源
    最近更新 更多