diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php index 8162dc8df7a9..8ff0e184228f 100644 --- a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php @@ -42,7 +42,7 @@ class MorphTo extends BelongsTo * * @var array */ - protected $typedEagerLoads = []; + protected $morphableEagerLoads = []; /** * Create a new morph to relationship instance. @@ -120,7 +120,7 @@ protected function getResultsByType($type) ->mergeConstraintsFrom($this->getQuery()) ->with(array_merge( $this->getQuery()->getEagerLoads(), - (array) ($this->typedEagerLoads[get_class($instance)] ?? []) + (array) ($this->morphableEagerLoads[get_class($instance)] ?? []) )); return $query->whereIn( @@ -269,11 +269,10 @@ public function getDictionary() * @param array $with * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ - public function withMorph(array $with) + public function morphWith(array $with) { - $this->typedEagerLoads = array_merge( - $this->typedEagerLoads, - $with + $this->morphableEagerLoads = array_merge( + $this->morphableEagerLoads, $with ); return $this; diff --git a/tests/Integration/Database/EloquentMorphEagerLoadingTest.php b/tests/Integration/Database/EloquentMorphEagerLoadingTest.php index b7ba197a6f75..c98cf4646e3b 100644 --- a/tests/Integration/Database/EloquentMorphEagerLoadingTest.php +++ b/tests/Integration/Database/EloquentMorphEagerLoadingTest.php @@ -1,6 +1,6 @@ with(['commentable' => function (MorphTo $morphTo) { - $morphTo->withMorph([Post::class => ['user']]); + $morphTo->morphWith([Post::class => ['user']]); }]) ->get(); @@ -63,7 +63,7 @@ public function test_with_morph_loading_with_single_relation() { $comments = Comment::query() ->with(['commentable' => function (MorphTo $morphTo) { - $morphTo->withMorph([Post::class => 'user']); + $morphTo->morphWith([Post::class => 'user']); }]) ->get();