Skip to content

Commit

Permalink
Added condition for nullable polymorphic relation
Browse files Browse the repository at this point in the history
  • Loading branch information
lBodia authored Oct 26, 2020
1 parent 3f0645c commit b6e52f6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] ?? []);
Expand Down Expand Up @@ -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] ?? []);
Expand Down

0 comments on commit b6e52f6

Please sign in to comment.