PHPackages                             roshangautam/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. roshangautam/presenter

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

roshangautam/presenter
======================

Simple Laravel View Presenters

v1.0.1(9y ago)0659MITPHPPHP &gt;=5.4.0

Since Jun 13Pushed 9y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

Easy View Presenters for Laravel
================================

[](#easy-view-presenters-for-laravel)

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.

```
composer require roshangautam/presenter
```

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 RoshanGautam\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 `RoshanGautam\Presenter\PresentableTrait` trait, which will automatically instantiate your presenter class.

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

```
