phpMick
4 months ago

Query builder to collection of models.

Posted 4 months ago by phpMick

I had just made some changes to my database and now the relationships are more complicated.

This means that to get $user->reports I am now using the query builder to retrieve the reports which were previously just a many-to-many:

 $results = DB::table('users AS u')
            ->select('r.*')
etc

This means that I am now getting a collection of stdClass instead of a collection of models. Is there a way to use a query to get a collection of models (in one db hit).

I tried using hydrate but it requires an array.

Cheers,

Mick

Please sign in or create an account to participate in this conversation.