php whereHas筛选器查询在laravel上出现问题

fkaflof6  于 2023-02-11  发布在  PHP
关注(0)|答案(1)|浏览(138)

大家好我想要的结果像我有许多产品和产品中有许多供应商和一个客户,所以当我搜索产品描述比显示所有产品,但我想像产品显示输出,但与客户ID匹配

$pi = Product::where('customer_id',$customerId)
            ->whereHas('supplier', function (Builder $query) use($search) {
                    $query->where('sys_state', '!=', '-1')
                    ->orWhere('name','LIKE','%' . $search . '%');
            })
            ->where('sys_state','!=','-1')
            ->orWhere('prd_our_item_no', 'LIKE', '%' . $search . '%')
            ->orWhere('prd_supplier_item', 'LIKE', '%' . $search . '%')
            ->orWhere('prd_description','LIKE','%' . $search . '%')
            ->get();

我尝试这个查询,但所有的产品显示当我搜索客户ID条件不工作

68bkxrlz

68bkxrlz1#

我尝试 Package 或where,但无法在其上搜索

$pi = Product::where('customer_id', $customerId)
        ->where('sys_state', '!=', '-1')
        ->whereHas('supplier', function (Builder $query) use ($search) {
            $query->where('sys_state', '!=', '-1')
            ->orWhere(function ($query) use ($search) {
                $query->where('name', 'LIKE', '%' . $search . '%')
                ->where('sys_state','!=','-1');
            });
        })
        ->orWhere(function ($query) use ($search, $customerId) {
            $query->where('prd_description', 'LIKE', '%' . $search . '%')
            ->where('sys_state', '!=', '-1')
            ->where('customer_id',$customerId);
        })
        ->orWhere(function($query) use($search, $customerId){
            $query->where('prd_supplier_item', 'LIKE', '%' . $search . '%')
            ->where('sys_state', '!=', '-1')
            ->where('customer_id',$customerId);
        })
        ->orWhere(function($query) use($search, $customerId){
            $query->where('prd_our_item_no', 'LIKE', '%' . $search . '%')
            ->where('sys_state', '!=', '-1')
            ->where('customer_id',$customerId);
        })
    ->get();

相关问题