From b6e52f66c90bd0b1c8c7d5e005186b63433b390a 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..32508d85564e 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] ?? []);