From 08c147d18717378286c3b7391a1c8bf37942cfc2 Mon Sep 17 00:00:00 2001 From: Bohdan Date: Mon, 26 Oct 2020 16:36:13 +0100 Subject: [PATCH] Added condition for nullable polymorphic relation --- src/Illuminate/Database/Eloquent/Model.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 1d7362deb058..a23c46350b8b 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -516,6 +516,10 @@ public function load($relations) */ public function loadMorph($relation, $relations) { + if (! $this->{$relation}) { + return $this; + } + $className = get_class($this->{$relation}); $this->{$relation}->load($relations[$className] ?? []); @@ -562,6 +566,10 @@ public function loadCount($relations) */ public function loadMorphCount($relation, $relations) { + if (! $this->{$relation}) { + return $this; + } + $className = get_class($this->{$relation}); $this->{$relation}->loadCount($relations[$className] ?? []);