Take a look at the following query:
$testQuery = Customer::where('company_id', auth()->user()->company_id);
$testQuery
->where('name', 'like', '%test%')
->orWhere('age', '>', 22);
dd($testQuery->toSql());
this produces the following SQL query:
select * from
customerswhere (company_id= ? andnamelike ? orage> ?) andcustomers.deleted_atis null
What I am after is something like this:
select * from
customerswherecompany_id= ? and (namelike ? orage> ?) andcustomers.deleted_atis null
How can I achieve this? i.e. the first where condition of company_id = ? more important than there rest of the filters on name and age?
Right now, based on how the query builder is constructing the query, I am seeing results from other company_id than the one I've specified in my query.