Because get()
function of Query builder returns an array while I need A collection, is there a way to convert Laravel Query Builder to Eloquent Builder?
$query_builder = DB::table('table1');
// different than
$eloquent_builder = Table1Model::select()
Laravel ships with a collect
helper to convert an array to a collection:
$collection = collect(DB::table('table1')->get());
There's a proposal on Github to have the next version of Laravel return collection instances from the query builder's get
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With