you need to wrap your orWhere's https://laravel.com/docs/9.x/queries#or-where-clauses
Feb 8, 2023
22
Level 13
whereHas filter query issue
hello guys i want result like i have many products and in products have many supplier and one customer so when i search product description than display all product but i want output like product display but match with customer id
here is my code
$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();
i try this query but all the product display when i search customer id where condition not work
Level 51
So this doesn't work? (reposted from above)
$pi = Product::where('customer_id',$customerId)
->whereNot('sys_state', '-1')
->where(function ($q) use($search) {
$q->whereHas('supplier', function (Builder $query) use($search) {
$query->where('name','LIKE','%' . $search . '%')
->whereNot('sys_state', '-1');
})
->orWhere('prd_our_item_no', 'LIKE', '%' . $search . '%')
->orWhere('prd_supplier_item', 'LIKE', '%' . $search . '%')
->orWhere('prd_description','LIKE','%' . $search . '%');
})
->get()
// whereNots just for readability
@psrz I think we crossed replied. I had corrected the Or.
1 like
Please or to participate in this conversation.