1

我可以问如何在对象中的laravel 5.3上做到这一点吗?我使用了本地范围方法。到目前为止,我对使用或在他们的对象中感到困惑。谢谢。

$sql = "SELECT * FROM `conversations` WHERE (`conversations`.`user_id` = 1 AND `conversations`.`chat_id` = 2) OR (`conversations`.`user_id` = 2 AND `conversations`.`chat_id` = 1)";
4

1 回答 1

2

尝试这个:

$conversation = Conversation::where(function($q) {
        $q->where('user_id', 1);
        $q->where('chat_id', 2);
    })->orWhere(function($q) {
        $q->where('user_id', 2);
        $q->where('chat_id', 1);
    })->get();

如果你想使用变量,别忘了用use().

于 2016-08-29T08:11:44.847 回答