如何在Laravel Eloquent中使用单个`where`和多个`or`条件在括号中。

huangapple go评论61阅读模式
英文:

How to use single where and multiple or in brackets in laravel eloquent

问题

DB::table('user')
    ->where('status', 1)
    ->where(function ($query) {
        $query->where('name', 'jones')
              ->orWhere('email', 'demo@gmail');
    })
    ->get();
英文:

I want to write this sql in laravel elequent.

      select * from user where status = 1 and (name = 'jones' or email = 'demo@gmail')

Thanks in advance.

答案1

得分: 1

你可以像这样使用Eloquent:

User::where('status', 1)->where('name', 'jones')->orWhere('email', 'demo@gmail')->get();
英文:

you can use eloquent like this

User::where('status',1)->where('name','jones')->orWhere('email','demo@gmail')->get();

huangapple
  • 本文由 发表于 2023年2月6日 02:35:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354601.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定