Laravel8 - Eloquent query builder: how add a raw query?
Hi to all,
I cannot write a Query Builder with a raw query inside.
I need to use the Query Builder 'cause I'm paginating and sorting the results via scoped query. Is it possible to inject that raw query that at the moment is commented out?
Taken alone, it works and return right recordset ;)
return $this
//->select(DB::raw("SELECT * FROM users WHERE id IN (SELECT user_id FROM users_licenses WHERE license_id IN (SELECT id FROM licenses WHERE agency_id IN (SELECT agency_id FROM users_agencies WHERE users_agencies.user_id = $user_id)))"))
->with('role', 'agencies', 'licenses', 'permissions')
->sort(request())->paginate($this->getPerPage());