【问题标题】:How to use AND and where caluse in Laravel 5.2 [duplicate]如何在 Laravel 5.2 中使用 AND 和 where 子句 [重复]
【发布时间】:2017-02-15 14:39:35
【问题描述】:

大家好,我在使用 laravel 5.2 时遇到了一些问题,我想运行这样的查询:

SELECT * FROM Chat
WHERE (From='1234' AND Number='420') OR WHERE (From='420' AND Number='1234');

为此,我正在尝试但没有得到确切的结果:

    $products = Chat::where('from', '=', $from)->where('number', '=', $number)->orwhere('from', '=', $number)->orwhere('number', '=', $from)->orderBy('id', 'ASC')->paginate(10);

我怎样才能使它工作没有这样的文档可以生成这样的查询。

【问题讨论】:

  • 使用 \DB::select("SELECT * FROM Chat WHERE (From='1234' AND Number='420') OR WHERE (From='420' AND Number='1234')" );
  • 这个问题对你要找的东西有很好的回答:stackoverflow.com/questions/19325312/…

标签: laravel-5 eloquent


【解决方案1】:

你可以试试这样的

$products = Chat::where([
['from', '=', $from],
['number', '=', $number],
])->orwhere([
['from', '=', $number],
['number', '=', $from],
])->get();

参考这里:How to create multiple where clause query using Laravel Eloquent?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多