vendredi 4 septembre 2020

Laravel Eloquent like relationship with whereHas

I am trying to serach inside a relationship and my query is

            $records = Store::orderBy($columnName,$columnSortOrder)
               ->where('store_id', 'like', '%' .$searchValue . '%')
                ->whereHas('customer', function ($query) use ($searchValue) {
                     $query->where('name', 'like', '%' .$searchValue . '%');
                })                 
               ->select('*')
               ->skip($start)
               ->take($rowperpage)
               ->get();

and returns a query

    SELECT * FROM `store` WHERE `store_id` LIKE '%San%' AND EXISTS ( SELECT * FROM `customers` 
WHERE `store`.`customer_id` = `customers`.`id` AND `name` LIKE '%San%') ORDER BY 
`inv_id` ASC LIMIT 10 OFFSET 0

What I want is or with relation

SELECT * FROM `store` WHERE `store_id` LIKE '%San%' OR EXISTS ( SELECT * FROM `customers` 
WHERE `store`.`customer_id` = `customers`.`id` AND `name` LIKE '%San%') ORDER BY 
`inv_id` ASC LIMIT 10 OFFSET 0


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire