mysql - Laravel Query builder查询相当于SQL查询?
问题描述
我的查询在这个 where 子句中运行正常。请告诉我什么会在 Laravel 中查询 builder 查询,相当于这个查询
WHERE (interest_request.sender_id = 6 or interest_request.to_user_id = 6)
AND interest_request.interest_status =2
and profiles.profile_id not in (6)
我正在使用以下查询生成器但不工作
where('to_user_id',$my_profile_id)->orwhere
('sender_id',$my_profile_id)->where('interest_status','2')
->whereNotIn('profiles.profile_id', $my_profile_id)
解决方案
在您的特定情况下,您必须使用嵌套where
子句:
->where(function ($query) use ($my_profile_id) {
$query->where('to_user_id', $my_profile_id)
->orWhere('sender_id', $my_profile_id);
})
->where('interest_status', 2)
->where('profile_id', '!=', $my_profile_id)
此外,如果列表中只有一个 id,则不需要使用whereIn
(or ) 查询。whereNotIn
推荐阅读
- google-apps-script - 如何将基于单元格值的行移动到其他工作表?
- reactjs - 如何在 React Native 中加载数据时显示 ActivityIndicator
- .net - 如何在 gitlab ci 中将 chrome 和 Firefox 的 selenium 驱动程序与 dotnet blazor 服务器集成以进行 e2e 测试
- java - Flappy Bird Pipes 如何在 Java 中随机化我用于学校的程序是 JGrasp
- dictionary - 如何处理 Haskell 中的“可能 [值]”列表?
- google-chrome-extension - Chrome 扩展 - 来自“launchWebAuthFlow”的令牌在一小时后过期,需要用户交互才能获得新的
- svg - 在 Web 浏览器中将 SVG 的字体大小与常规文本匹配
- javascript - 相同比例的 d3.jzoom 无法正常工作
- javascript - 在 Node.js 应用程序中处理第 3 方 API 令牌
- node.js - 如何使用 let 和 piplines 改进我的性能查询 - Mongoose