PHPackages                             hemp/presenter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. hemp/presenter

ActiveProject[Framework](/categories/framework)

hemp/presenter
==============

Easy Model Presenters in Laravel

v3.0.0(2y ago)247592.6k—5%151MITPHP

Since Sep 6Pushed 2y ago6 watchersCompare

[ Source](https://github.com/davidhemphill/presenter)[ Packagist](https://packagist.org/packages/hemp/presenter)[ RSS](/packages/hemp-presenter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (28)Used By (1)

🌿 Hemp Presenter
================

[](#-hemp-presenter)

This package makes it fast, fun, and profitable to decorate your Eloquent models for presentation in views, PDFs, CSV files, or anywhere else in your project.

For a little primer on the problems presenters solve, take a look at this article: [Presenters in Laravel](https://gistlog.co/davidhemphill/1b7c749cdd6520eb19320c208ef32433).

Installation
------------

[](#installation)

Install the package via [Composer](https://getcomposer.org/):

```
composer require hemp/presenter

```

In Laravel 5.5+, the package's service provider should be auto-discovered, so you won't need to register it. If for some reason you need to register it manually you can do so by adding it to the `providers` array in `config/app.php`:

```
'providers' => [
    // ...
    Hemp\Presenter\PresenterServiceProvider::class,
],
```

Creating `Presenter` Classes
----------------------------

[](#creating-presenter-classes)

You can easily generate a `Presenter` class by calling the `make:presenter` Artisan command:

```
php artisan make:presenter ApiPresenter
```

This will generate an empty `Presenter` class inside of `app/Presenters`.

Customizing `Presenter` Classes
-------------------------------

[](#customizing-presenter-classes)

At their core, presenters are simple classes designed to encapsulate complex or repetitive view logic. What makes `hemp/presenter` nice is it allows you to attach magic accessors to these `Presenter` objects all the while allowing for the typical serialization workflow of using regular `Model` objects and collections. For example, take this `ApiPresenter` class:

```
