From 1eddcfd728045f68597d3dfa9a54da38a4995bf2 Mon Sep 17 00:00:00 2001 From: Antonio Carlos Ribeiro Date: Wed, 23 Jul 2014 13:51:03 -0300 Subject: [PATCH 1/2] Allow entity's methods calls --- src/Laracasts/Presenter/Presenter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Laracasts/Presenter/Presenter.php b/src/Laracasts/Presenter/Presenter.php index 54c4cb7..220f51f 100644 --- a/src/Laracasts/Presenter/Presenter.php +++ b/src/Laracasts/Presenter/Presenter.php @@ -28,7 +28,12 @@ public function __get($property) return $this->{$property}(); } + if (method_exists($this->entity, $property)) + { + return $this->entity->{$property}(); + } + return $this->entity->{$property}; } -} \ No newline at end of file +} From da140396a4d4b643450a7e9d5ec9da5c4cc8d1c6 Mon Sep 17 00:00:00 2001 From: Antonio Carlos Ribeiro Date: Wed, 23 Jul 2014 15:23:30 -0300 Subject: [PATCH 2/2] Update Presenter.php --- src/Laracasts/Presenter/Presenter.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Laracasts/Presenter/Presenter.php b/src/Laracasts/Presenter/Presenter.php index 220f51f..6186d16 100644 --- a/src/Laracasts/Presenter/Presenter.php +++ b/src/Laracasts/Presenter/Presenter.php @@ -28,12 +28,26 @@ public function __get($property) return $this->{$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 $this->entity->{$property}; + return null; } }