PHPackages                             creanso\_laracasts/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. creanso\_laracasts/presenter

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

creanso\_laracasts/presenter
============================

Simple view presenters

0.2.4(5y ago)0182MITPHPPHP &gt;=5.4.0

Since Mar 24Pushed 4y agoCompare

[ Source](https://github.com/creanso-niziol/Presenter)[ Packagist](https://packagist.org/packages/creanso_laracasts/presenter)[ RSS](/packages/creanso-laracasts-presenter/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (11)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.

```
