Skip to content

Commit

Permalink
Use a single chain with a flatMap to perform the same operation (#13741)
Browse files Browse the repository at this point in the history
  • Loading branch information
phroggyy authored and taylorotwell committed May 27, 2016
1 parent 8e394fc commit e3986a4
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Illuminate/Database/Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,11 @@ protected function getEagerLoadsForInstance(Model $instance)
{
$eagers = BaseCollection::make($this->query->getEagerLoads());

$eagers = $eagers->filter(function ($constraint, $relation) {
return $eagers->filter(function ($constraint, $relation) {
return Str::startsWith($relation, $this->relation.'.');
});

return $eagers->keys()->map(function ($key) {
return Str::replaceFirst($this->relation.'.', '', $key);
})->combine($eagers)->merge($instance->getEagerLoads())->all();
})->flatMap(function ($constraint, $relation) {
return [Str::replaceFirst($this->relation.'.', '', $relation) => $constraint];
})->merge($instance->getEagerLoads())->all();
}

/**
Expand Down

0 comments on commit e3986a4

Please sign in to comment.