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

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

caffeinated/presenter
=====================

Laravel 5 View Presenters

v2.1(10y ago)1817.8k6MITPHPPHP &gt;=5.5.9

Since Jun 12Pushed 6y ago2 watchersCompare

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

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

This package has been abandoned and is no longer maintained.
============================================================

[](#this-package-has-been-abandoned-and-is-no-longer-maintained)

Caffeinated Presenter
=====================

[](#caffeinated-presenter)

[![Laravel 5.1](https://camo.githubusercontent.com/05076f1468adbd2ff88c746e1d499486fe3755747a047b2f42949a583c4884b2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e312d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![Laravel 5.2](https://camo.githubusercontent.com/3c5fafdd636fa4b58339ff9c390671fac70d00e2654590261153d96a4de251db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e322d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![Source](https://camo.githubusercontent.com/6297a55f283744e7c227ef75e439c98815d8951ea700300c6d6d905c1678f732/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6361666665696e617465642f70726573656e7465722d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/caffeinated/presenter)[![License](https://camo.githubusercontent.com/30597ff9a350144f03bffdd9183e16468e0b3ca1193e1d08591d992622738d55/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://tldrlegal.com/license/mit-license)

Laravel 5 view presenters, originally developed after the Laracasts video tutorial on the same topic: [View Presenters From Scratch](https://laracasts.com/lessons/view-presenters-from-scratch).

Presenters allow you to manipulate any form of data for display within a view file. A simple example would be if you have a user entity with fields for the first and last names, how would you simply display the full name of the user within your view file? The most common solution would be something like the following:

```
Hello, {{ $user->first_name }} {{ $user->last_name }}!
```

Which works, but *every* time you need to display a user's full name, you'd have to type this out. What if instead it was something like this:

```
Hello, {{ $user->present()->fullName }}!
```

Isn't that much more readable than the previous example? Now you may argue that you could add this type of logic directly to your model class, *which you could*, but then you'll find that your model classes are riddled with methods that are manipulating view logic. I don't believe model entities should be responsible for this. Their **only job** is to pull the requested data from the database and hand it over. *That's it.*

Quick Installation
------------------

[](#quick-installation)

Begin by installing the package through Composer.

```
composer require caffeinated/presenter=~2.0

```

And that's it! With your coffee in reach, start building out some awesome presenters!

Usage
-----

[](#usage)

### 1. Pull in trait

[](#1-pull-in-trait)

Within your model, simply pull in the `Caffeinated\Presenter\Traits\PresentableTrait` trait, which will automatically instantiate the Caffeinated Presenter class.

```
...

use Caffeinated\Presenter\Traits\PresentableTrait;

class Example extends Eloquent
{
	use PresentableTrait;

	...
}
```

### 2. Define your presenter class

[](#2-define-your-presenter-class)

Define a protected `$presenter` variable pointing to the namespace of your presenter class.

```
...

use Caffeinated\Presenter\Traits\PresentableTrait;

class Example extends Eloquent
{
	use PresentableTrait;

	protected $presenter = 'App\Presenters\Page';

	...
}
```

### 3. Create your presenter class

[](#3-create-your-presenter-class)

Create a new class as defined within your model earlier - in our case we'll create a new directory within the `app` directory called `Presenters`, and create a `Page` file. Presenters should extend the abstract `Caffeinated\Presenter\Presenter` class.

```
