Zaheer
4 months ago
236
19
Eloquent

Add new column/element to collection

Posted 4 months ago by Zaheer

I can update a collection with following code :

foreach ($rslt as $row) {
    $getacc = $acc->where('code',$row->code)->first();
    $getacc->update(['clbal' => $row->total]);
}

This requires that clbal column must be present in $getacc. What if I want to add this column to collection. Is there any Insert() function available.

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