From 7cd875f71f14a81b43b8c42431ebfffdbd063dca Mon Sep 17 00:00:00 2001 From: Pingchieh Date: Fri, 25 May 2018 23:29:40 +0800 Subject: [PATCH 1/2] Remove null attributes/relationships in loadMorph before grouped by class name. --- src/Illuminate/Database/Eloquent/Collection.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 261902703c5d..a10339011b51 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -135,6 +135,9 @@ protected function loadMissingRelation(Collection $models, array $path) public function loadMorph($relation, $relations) { $this->pluck($relation) + ->reject(function ($value, $key) { + return is_null($value); + }) ->groupBy(function ($model) { return get_class($model); }) From 4476224d06d52027fade64d8cbb51413571b20b9 Mon Sep 17 00:00:00 2001 From: Pingchieh Date: Sat, 26 May 2018 03:33:39 +0800 Subject: [PATCH 2/2] Use filter() without a callback instead. --- src/Illuminate/Database/Eloquent/Collection.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index a10339011b51..4114d8afe3d6 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -135,9 +135,7 @@ protected function loadMissingRelation(Collection $models, array $path) public function loadMorph($relation, $relations) { $this->pluck($relation) - ->reject(function ($value, $key) { - return is_null($value); - }) + ->filter() ->groupBy(function ($model) { return get_class($model); })