Is there a built in way to return an array of standard class objects from an eloquent model instead of an eloquent collection? For example one could do:
return json_decode(json_encode(\App\User::where('status', 'active')
->get()->toArray()));
However this seems like unnecessary overhead since we would be converting the response to an eloquent collection, then to an array, then json encoding that array and then json decoding that string...
The reason I am after this functionality is because I am in the process of breaking apart a large enterprise application that was originally created with all business logic within controller methods (which is proving difficult to maintain). I am imposing a standard within the project that all access to the database (using eloquent models and query builder) must be performed in the service class of that particular entity, and that data returned from service classes should be of primitive php types so that if the decision ever comes down to replace eloquent with another orm or swap mysql out completely, these service classes are the only thing that would need to be rewritten to do so (kind of like a repository pattern, but not really since the service classes contain business logic as well as database access via model classes)
I suppose one solution to this could be to extend the base eloquent class to contain a method such as toObj() (probably not the best name...good thing I'm not on the standards committee ;) )