PHPackages                             eru/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. [Templating &amp; Views](/categories/templating)
4. /
5. eru/presenter

ActiveLibrary[Templating &amp; Views](/categories/templating)

eru/presenter
=============

Simple view presenters

1.0.2(4y ago)015MITPHPPHP &gt;=5.4.0

Since Mar 24Pushed 3y agoCompare

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

READMEChangelog (2)Dependencies (3)Versions (13)Used By (0)

Easy View Presenters
====================

[](#easy-view-presenters)

So 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.

- Should that logic be hard-coded into the view? **No**.
- Should we instead store the logic in the model? **No again!**

Instead, leverage view presenters. That's what they're for! This package provides one such implementation.

Install
-------

[](#install)

Pull this package in through Composer.

```
{
    "require": {
        "laracasts/presenter": "0.1.*"
    }
}
```

Usage
-----

[](#usage)

The first step is to store your presenters somewhere - anywhere. These will be simple objects that do nothing more than format data, as required.

Here's an example of a presenter.

```
use Laracasts\Presenter\Presenter;

class UserPresenter extends Presenter {

    public function fullName()
    {
        return $this->first . ' ' . $this->last;
    }

    public function accountAge()
    {
        return $this->created_at->diffForHumans();
    }

}
```

Next, on your entity, pull in the `Laracasts\Presenter\PresentableTrait` trait, which will automatically instantiate your presenter class.

Here's an example - maybe a Laravel `User` model.

```
