Laravel: change a raw query in a “query-builder” or “eloquent” one
问题 I have this Laravel Query Builder snippet that is working fine: $records = DB::table('users') ->select( DB::raw('users.*, activations.id AS activation, (SELECT roles.name FROM roles INNER JOIN role_users ON roles.id = role_users.role_id WHERE users.id = role_users.user_id LIMIT 1) AS role') ) ->leftJoin('activations', 'users.id', '=', 'activations.user_id') ->where('users.id', '<>', 1) ->orderBy('last_name') ->orderBy('first_name') ->paginate(10); Is there a way to avoid use of raw queries