From e872f77a63cc93d2cf006a7b876215432678bda0 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Sun, 2 Sep 2018 03:44:57 +0200 Subject: [PATCH] Fix MorphTo lazy loading and withoutGlobalScopes() --- src/Illuminate/Database/Eloquent/Relations/MorphTo.php | 2 ++ .../Database/EloquentMorphToGlobalScopesTest.php | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php index e25b3f52182f..dd989e477295 100644 --- a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php @@ -231,6 +231,8 @@ public function dissociate() */ public function withoutGlobalScopes(array $scopes = null) { + $this->getQuery()->withoutGlobalScopes(); + $this->macroBuffer[] = [ 'method' => __FUNCTION__, 'parameters' => [$scopes], diff --git a/tests/Integration/Database/EloquentMorphToGlobalScopesTest.php b/tests/Integration/Database/EloquentMorphToGlobalScopesTest.php index c55bee882e45..4ca62cf08d53 100644 --- a/tests/Integration/Database/EloquentMorphToGlobalScopesTest.php +++ b/tests/Integration/Database/EloquentMorphToGlobalScopesTest.php @@ -63,6 +63,14 @@ public function test_without_global_scopes() $this->assertNotNull($comments[0]->commentable); $this->assertNotNull($comments[1]->commentable); } + + public function test_lazy_loading() + { + $comment = Comment::latest('id')->first(); + $post = $comment->commentable()->withoutGlobalScopes()->first(); + + $this->assertNotNull($post); + } } class Comment extends Model