From 6d68185cfd8c11a058c8cca31eda93364d62ae17 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Mon, 30 May 2016 10:19:10 -0400 Subject: [PATCH] Use keyBy instead of flatMap --- src/Illuminate/Database/Eloquent/Relations/MorphTo.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php index 8191333051f9..20087fc7f1d9 100644 --- a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php @@ -194,12 +194,12 @@ protected function getResultsByType($type) */ protected function getEagerLoadsForInstance(Model $instance) { - $eagers = BaseCollection::make($this->query->getEagerLoads()); + $relations = BaseCollection::make($this->query->getEagerLoads()); - return $eagers->filter(function ($constraint, $relation) { + return $relations->filter(function ($constraint, $relation) { return Str::startsWith($relation, $this->relation.'.'); - })->flatMap(function ($constraint, $relation) { - return [Str::replaceFirst($this->relation.'.', '', $relation) => $constraint]; + })->keyBy(function ($constraint, $relation) { + return Str::replaceFirst($this->relation.'.', '', $relation); })->merge($instance->getEagerLoads())->all(); }