我正在尝试更新已创建并包含数据的Eloquent集合。
我想做的是:
。
$fee_collection = new Collection();
$count = [];
foreach($feedetail->fee as $feee){
if(in_array($feee->id, $count)){ //check for duplicate ids
$fee_collect = $fee_collection->where('id',$feee->id)->first();
$fee_collect->pivot->amount = $fee_collect->pivot->amount + $feee->pivot->amount;
$fee_collect->pivot->line_discount = $fee_collect->pivot->line_discount + $feee->pivot->line_discount;
$fee_collect->pivot->month_year = str_replace('-28','',$fee_collect->pivot->month_year).",".str_replace('-28','',$feee->pivot->month_year);
// $fee_collection->fill($fee_collect)->save();
} else {
$fee_collection[] = $feee;
$count[] = $feee->id;
}
}
dd($fee_collect);
我应该得到的是一个包含数组的新集合,这些数组包含来自包含重复ID的原始数组的合并数据。