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

AbandonedArchivedLibrary

halaei/presenter
================

presenter for eloquent

1.0.0(11y ago)0133PHPPHP &gt;=5.4.0

Since Aug 15Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (6)Used By (0)

Presenter
=========

[](#presenter)

This is an alternative implementation of [laracasts/presenter](https://github.com/laracasts/Presenter) with some added features. Some parts of this document is copy-past!

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.

**PS**: Using repository pattern, this package suggests that repository functions should return presenter instead of model and presenter collection instead of eloquent collection.

\#Installation

```
{
    "require": {
        "halaei/presenter": "0.*"
    }
}
```

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

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

```
