{"id":23107944,"url":"https://github.com/andrewdyer/view-presenters","last_synced_at":"2026-03-09T14:06:54.155Z","repository":{"id":56948014,"uuid":"269687754","full_name":"andrewdyer/view-presenters","owner":"andrewdyer","description":"A clean, reusable solution for separating presentation logic from models and views in PHP applications","archived":false,"fork":false,"pushed_at":"2025-05-27T16:33:38.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-02T11:19:29.269Z","etag":null,"topics":["laravel","php","presenters","view","view-presenter"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewdyer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-06-05T15:39:59.000Z","updated_at":"2025-05-27T16:33:41.000Z","dependencies_parsed_at":"2025-02-09T10:41:36.932Z","dependency_job_id":"c72fb5f1-1f59-40bd-a741-b680c304343f","html_url":"https://github.com/andrewdyer/view-presenters","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/andrewdyer/view-presenters","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fview-presenters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fview-presenters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fview-presenters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fview-presenters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewdyer","download_url":"https://codeload.github.com/andrewdyer/view-presenters/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fview-presenters/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30297935,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T13:46:43.843Z","status":"ssl_error","status_checked_at":"2026-03-09T13:46:42.821Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","php","presenters","view","view-presenter"],"created_at":"2024-12-17T01:16:28.730Z","updated_at":"2026-03-09T14:06:54.141Z","avatar_url":"https://github.com/andrewdyer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# View Presenters\n\nA clean, reusable solution for separating presentation logic from models and views in PHP applications.\n\n## ⚖️ License\n\nLicensed under the [MIT license](https://opensource.org/licenses/MIT) and is free for private or commercial projects.\n\n## ✨ Introduction\n\nWhen models or views become bloated with formatting and derived data logic, **View Presenters** offer a way to offload that responsibility into dedicated presenter classes. This improves separation of concerns, testability, and reusability.\n\n## 📦 Installation\n\nInstall via Composer:\n\n```shell\ncomposer require andrewdyer/view-presenters\n```\n\n## 🚀 Getting Started\n\n### 1️⃣ Define a Presenter\n\nCreate a presenter class that extends `Presenter`:\n\n```php\n\u003c?php\n\nnamespace App\\Presenters;\n\nuse App\\Models\\User;\nuse Anddye\\ViewPresenters\\Presenter;\n\nclass UserPresenter extends Presenter\n{\n    public function __construct(readonly private User $user) {}\n\n    public function defaultAttributes(): array\n    {\n        return [\n            'id' =\u003e $this-\u003euser-\u003egetId(),\n            'forename' =\u003e $this-\u003euser-\u003egetForename(),\n            'surname' =\u003e $this-\u003euser-\u003egetSurname(),\n        ];\n    }\n\n    public function name(): string\n    {\n        return $this-\u003euser-\u003egetForename() . ' ' . $this-\u003euser-\u003egetSurname();\n    }\n}\n```\n\n### 2️⃣ Attach Presenter to Model\n\nUse the `HasPresenters` trait in your model and define available presenters:\n\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse App\\Presenters\\UserPresenter;\nuse Anddye\\ViewPresenters\\HasPresenters;\n\nclass User {\n    use HasPresenters;\n\n    protected int $id;\n    protected string $forename;\n    protected string $surname;\n    protected array $presenters = [\n        'default' =\u003e UserPresenter::class,\n    ];\n\n    public function getId(): int\n    {\n        return $this-\u003eid;\n    }\n\n    public function getForename(): string\n    {\n        return $this-\u003eforename;\n    }\n\n    public function getSurname(): string\n    {\n        return $this-\u003esurname;\n    }\n}\n```\n\n## 📖 Usage\n\nAccess presenter attributes via the `present()` method:\n\n```php\n$user = new User();\n$user-\u003esetId(1);\n$user-\u003esetForename('John');\n$user-\u003esetSurname('Doe');\n\necho $user-\u003epresent()-\u003ename; // \"John Doe\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewdyer%2Fview-presenters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewdyer%2Fview-presenters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewdyer%2Fview-presenters/lists"}