From ec81088570cb4ae31f22c33d2e193d642c24b851 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Sun, 2 Sep 2018 15:49:42 +0200 Subject: [PATCH] Fix MorphTo lazy loading and withoutGlobalScopes() (#25406) --- 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..95acb81c1bac 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($scopes); + $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