From b817a02eea4043c33781fd5dcc3ea6bac5bdfa62 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Tue, 15 Feb 2022 12:38:28 +0300 Subject: [PATCH] Fix loadAggregate not correctly applying casts --- src/Illuminate/Database/Eloquent/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index ff9b2747fe3e..ee583f23e551 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -92,7 +92,7 @@ public function loadAggregate($relations, $column, $function = null) $this->each(function ($model) use ($models, $attributes) { $extraAttributes = Arr::only($models->get($model->getKey())->getAttributes(), $attributes); - $model->forceFill($extraAttributes)->syncOriginalAttributes($attributes); + $model->forceFill($extraAttributes)->syncOriginalAttributes($attributes)->mergeCasts($models->get($model->getKey())->getCasts()); }); return $this;