mardi 28 mai 2019

or where clause - Laravel eloquent

I have this query:

if($keyword){
    array_push($where, ['name_en', 'LIKE', '%'.$keyword.'%']);
}

The problem is that I have and name_fr column and I need to use OR clause - array_push($where, ['name_fr', 'LIKE', '%'.$keyword.'%']).

I can't use ->orWhere, because I have many dynamic search fields - they may exists or not.

For the example:

if($fromPrice){
    array_push($where, ['price', '>=', $fromPrice]);
}
if($toPrice){
    array_push($where, ['price', '<=', $toPrice]);
}

And the query is:

$cars= Property::with(array(
    'photos'=>function($query){
            $query->select(['car_id', 'name']);
        }
))->where($where)->paginate(10);

I need to select WHERE name_en LIKE %val% OR name_fr LIKE %val% with another queries.

Is there a way to use somehow where, 'OR' and LIKE in the above way including another values from $where array ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire