Overloading newQuery and put the rest of the query in scope
I'm working on an application where a lot of models have a Company Filter which looks a bit like:
public function newQuery($excludeDeleted = true) {
$query = parent::newQuery($excludeDeleted);
if (!authUserIsAdmin()) {
$query->where('company_id', Auth::user()->company_id);
}
return $query;
}
But now if we use an orWhere clause in our queries the company_id part is bypassed by the OR clause. Is there a way to put the whole query to come in a scope (between parentheses) and combine that with an AND company_id = ? at the end?