Prior Laravel 6 when i filled a model using a raw query, fields created in this query were assigned using the fill function even though the model does not have these fields in the database. When i upgraded from Laravel 5.8 this is no longer working. Is there any workaround for this?
Code example:
$sql = "SELECT SUM(S.amount) AS total_amount, SI.* [...]"
$data = \DB::select($sql)
$collection = [];
foreach($data as $row) {
$item = new Item(); // Extends Eloquent Model
$item->fill((Array) $row);
$item->id = $row->id;
$collection[] = $item;
}
return collect($collection);
In this case the attribute total_amount is missing, but it was there prior upgrading to Laravel 6.