{"id":13396014,"url":"https://github.com/laracasts/Presenter","last_synced_at":"2025-03-13T22:31:27.972Z","repository":{"id":15317000,"uuid":"18047027","full_name":"laracasts/Presenter","owner":"laracasts","description":"Easy view presenters in your apps.","archived":false,"fork":false,"pushed_at":"2024-05-10T00:36:12.000Z","size":18,"stargazers_count":864,"open_issues_count":25,"forks_count":111,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-09-08T13:44:58.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/laracasts/presenter","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"caioariede/django-location-field","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laracasts.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2014-03-24T00:12:13.000Z","updated_at":"2024-08-30T06:54:50.000Z","dependencies_parsed_at":"2022-08-08T16:00:03.401Z","dependency_job_id":"1ca18f3a-82ee-4757-9b3e-047e919cd626","html_url":"https://github.com/laracasts/Presenter","commit_stats":{"total_commits":19,"total_committers":7,"mean_commits":"2.7142857142857144","dds":0.3157894736842105,"last_synced_commit":"4353fb5a1a3b9b9073db66fd823eaaf04c0c5db0"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracasts%2FPresenter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracasts%2FPresenter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracasts%2FPresenter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracasts%2FPresenter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laracasts","download_url":"https://codeload.github.com/laracasts/Presenter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241367916,"owners_count":19951447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-07-30T18:00:37.700Z","updated_at":"2025-03-13T22:31:27.703Z","avatar_url":"https://github.com/laracasts.png","language":"PHP","readme":"# Easy View Presenters\n\nSo you have those scenarios where a bit of logic needs to be performed before some data (likely from your entity) is displayed from the view.\n\n- Should that logic be hard-coded into the view? **No**.\n- Should we instead store the logic in the model? **No again!**\n\nInstead, leverage view presenters. That's what they're for! This package provides one such implementation.\n\n## Install\n\nPull this package in through Composer.\n\n```js\n{\n    \"require\": {\n        \"laracasts/presenter\": \"0.1.*\"\n    }\n}\n```\n\n## Usage\n\nThe first step is to store your presenters somewhere - anywhere. These will be simple objects that do nothing more than format data, as required.\n\nHere's an example of a presenter.\n\n```php\nuse Laracasts\\Presenter\\Presenter;\n\nclass UserPresenter extends Presenter {\n\n    public function fullName()\n    {\n        return $this-\u003efirst . ' ' . $this-\u003elast;\n    }\n\n    public function accountAge()\n    {\n        return $this-\u003ecreated_at-\u003ediffForHumans();\n    }\n\n}\n```\n\nNext, on your entity, pull in the `Laracasts\\Presenter\\PresentableTrait` trait, which will automatically instantiate your presenter class.\n\nHere's an example - maybe a Laravel `User` model.\n\n```php\n\u003c?php\n\nuse Laracasts\\Presenter\\PresentableTrait;\n\nclass User extends \\Eloquent {\n\n    use PresentableTrait;\n\n    protected $presenter = 'UserPresenter';\n\n}\n```\n\nThat's it! You're done. Now, within your view, you can do:\n\n```php\n    \u003ch1\u003eHello, {{ $user-\u003epresent()-\u003efullName }}\u003c/h1\u003e\n```\n\nNotice how the call to the `present()` method (which will return your new or cached presenter object) also provides the benefit of making it perfectly clear where you must go, should you need to modify how a full name is displayed on the page.\n\nHave fun!\n\nJeffrey @ [https://laracasts.com](https://laracasts.com)","funding_links":[],"categories":["Popular Packages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaracasts%2FPresenter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaracasts%2FPresenter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaracasts%2FPresenter/lists"}