gpt4 book ai didi

mysql - 将此 SQL 查询作为 Elequent 语句的最佳方法是什么

转载 作者:行者123 更新时间:2023-11-29 00:02:14 24 4
gpt4 key购买 nike

我需要以下 sql 语句来转换为 Laravel Eloquent。尝试了几种方法,但都失败了。

SELECT * FROM `conversations` where `type` = 'open' 
AND `sender_id`=2 AND ((`deleted_by_sender` IS NULL )
AND (`deleted_by_sender` IS NULL OR `deleted_by_receiver` IS NULL ))
OR `receiver_id` = 2 AND ((`deleted_by_sender` IS NULL )
AND (`deleted_by_sender` IS NULL OR `deleted_by_receiver` IS NULL ))

提前谢谢你。

最佳答案

你可以用这种方式在 eloquent 中执行你的查询,我假设你有一个名为 Conversation 的模型

Conversation::where('type', 'open')
->where('sender_id', 2)
->whereNull('deleted_by_sender')
->where(function ($query) {
return $query->whereNull('deleted_by_sender')
->orWhereNull('deleted_by_receiver');
})->orWhere('receiver_id', 2)
->whereNull('deleted_by_sender')
->where(function ($query) {
return $query->whereNull('deleted_by_sender')
->orWhereNull('deleted_by_receiver');
})->get();

这些代码未经测试,直接从您的 sql 查询中翻译而来

关于mysql - 将此 SQL 查询作为 Elequent 语句的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29253526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com