请问这种sql语句用laravel怎么写呢

请问这种sql语句用laravel怎么写呢
select * from `enterprise_company` where `enable` = 1 and (
(`local_tax_company_id` = 22 and `company_id` = 2 and `conglomerate_id` = 1) or 
(`local_tax_company_id` = 26 and `company_id` = 2 and `conglomerate_id` = 1) or 
(`local_tax_company_id` = 20 and `company_id` = 3 and `conglomerate_id` = 1)
) and `company_configs`.`deleted_at` is null

里面的(local_tax_company_id = 3 and company_id =2 and conglomerate_id =1)不确定可能有多个

我用laravel
EnterpriseCompany::query()
            ->where('enable', EnterpriseCompany::ENABLE)
            ->where(function ($q) use ($data) {
               foreach ($data as $value) {
                        $s->orWhere($value);
                    }
            })
            ->dd();
打印出来是这样
select * from `enterprise_company` where  `enable` = 1 and (
(`local_tax_company_id` = 22 or `company_id` = 2 or `conglomerate_id` = 1) or (`local_tax_company_id` = 26 or `company_id` = 2 or `conglomerate_id` = 1) or (`local_tax_company_id` = 20 or `company_id` = 3 or `conglomerate_id` = 1)
) and `enterprise_company`.`deleted_at` is null

该怎么写

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 6
EnterpriseCompany::query()
            ->where('enable', EnterpriseCompany::ENABLE)
            ->where(function ($q) use ($data) {
               foreach ($data as $value) {
                        $q->orWhere(function($q){
                            $q->where(...)//伪代码 结构应该是这样的
                        });
                    }
            })
            ->dd();
3周前 评论

先在外面拼接好每一个where

        $wheres = [];
        foreach ($data as $datum) {
            $wheres[] = function($query)use($datum){
                $query->where("local_tax_company_id",$datum["local_tax_company_id"])
                    ->where("company_id",$datum["company_id"])
                    ->where("conglomerate_id",$datum["conglomerate_id"]);
            };
        }
        EnterpriseCompany::query()
            ->where(function ($q) use ($wheres) {
                foreach ($wheres as $value) {
                    $q->orWhere($value);
                }
            })
            ->dd();
3周前 评论
EnterpriseCompany::query()
            ->where('enable', EnterpriseCompany::ENABLE)
            ->where(function ($q) use ($data) {
               foreach ($data as $value) {
                  $s->where(function($q1) use(value){
                         $q1->orWhere($value);
                    });
               }
            })
            ->dd();

再嵌套一层应该就可以了,至于value的值根据你的业务去调整

3周前 评论
Deftlhhhhh (楼主) 3周前
CodeUndefined (作者) 3周前
use Illuminate\Database\Eloquent\Builder as QueryBuilder;

        $wheres = [
            ['local_tax_company_id' => '1111', 'company_id' => '1222'],
            ['local_tax_company_id' => '2111', 'company_id' => '2222'],
            ['local_tax_company_id' => '3111', 'company_id' => '3222'],
        ];
        EnterpriseCompany::::query()
            ->where('enable', EnterpriseCompany::ENABLE)
            ->where(static function (QueryBuilder $query) use ($wheres){
                foreach ($wheres as $where) {
                    $query->orWhere(static function (QueryBuilder $query) use ($where){
                        $query->where($where);
                    });
                }
            })
            ->dd();
3周前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!