我该如何查询在Laravel中构建

发布于 2025-02-11 02:35:20 字数 124 浏览 1 评论 0原文

如果我想在sql中做这样的事情: 从表中选择 * id = 1111 (列1为null或column2 ='sample')

我尝试使用“ - > wery(..) - > orwherenull(...)

If i want to make something like this in sql:
SELECT * FROM table
WHERE id = 1111
AND (column1 is null OR column2 = 'sample')

I try with "->where(..)->orWhereNull(...)", but it is not my point (like without () is query)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心在旅行 2025-02-18 02:35:20

在Laravel中使用逻辑分组,谢谢Aynber:

->where('id', 1111)
->where(function ($q) {
            $q->where('column2', 'sample')
            ->orWhereNull('column1');
        })

Use Logical Grouping in Laravel, thanks aynber:

->where('id', 1111)
->where(function ($q) {
            $q->where('column2', 'sample')
            ->orWhereNull('column1');
        })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文