diff --git a/src/Laracasts/Presenter/Presenter.php b/src/Laracasts/Presenter/Presenter.php index 54c4cb7..6186d16 100644 --- a/src/Laracasts/Presenter/Presenter.php +++ b/src/Laracasts/Presenter/Presenter.php @@ -28,7 +28,26 @@ public function __get($property) return $this->{$property}(); } - return $this->entity->{$property}; + try + { + return $this->entity->{$property}; + } + catch(\LogicException $e) + { + // While trying to access an unavailable relationship as + // an existing model method, Laravel Eloquent (getRelationshipFromMethod) + // may throw a LogicException, with the message + // "Relationship method must return an object of type + // Illuminate\Database\Eloquent\Relations\Relation", + // ignore it and try to call the actual method. + } + + if (method_exists($this->entity, $property)) + { + return $this->entity->{$property}(); + } + + return null; } -} \ No newline at end of file +}