Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow entity's methods calls #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Laracasts/Presenter/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
}