Skip to content

Commit ecf46dd

Browse files
authored
Merge pull request #1 from evals/update-morph-to-to-return-null-if-necessary
Have MorphTo return null if no result
2 parents d2cc27e + 407e252 commit ecf46dd

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/Illuminate/Database/Eloquent/Relations/MorphTo.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public function __construct(Builder $query, Model $parent, $foreignKey, $otherKe
5252

5353
parent::__construct($query, $parent, $foreignKey, $otherKey, $relation);
5454
}
55+
56+
/**
57+
* Get the results of the relationship.
58+
*
59+
* @return mixed
60+
*/
61+
public function getResults()
62+
{
63+
if ( ! $this->otherKey) return;
64+
65+
return $this->query->first();
66+
}
5567

5668
/**
5769
* Set the constraints for an eager load of the relation.

0 commit comments

Comments
 (0)