【问题标题】:laravel sql statement - how to add additional clause to where isnot - 'where' '!=' ORlaravel sql 语句 - 如何在 where isnot 中添加附加子句 - 'where' '!=' OR
【发布时间】:2019-06-26 11:01:39
【问题描述】:

我想从数据库中获取除 2 之外的所有用户。

我曾经用这段代码抓取除一个之外的所有内容:

$users = User::where('name', '!=','name1')->get();

但我不确定如何为此添加其他名称。

非常感谢,

迈克

【问题讨论】:

  • 您还可以将 where(...)->where(...) 子句链接在一起。

标签: php sql laravel eloquent


【解决方案1】:

你可以使用WhereNotIn

Documentation

$users = User::whereNotIn('name', ['name1', 'name2', 'name3'])->get();

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2011-10-22
    • 2020-11-28
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2021-04-25
    • 1970-01-01
    相关资源
    最近更新 更多