PHPackages                             ryannielson/prez - 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. ryannielson/prez

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

ryannielson/prez
================

Easily create presenters for your objects.

2.0.0(10y ago)22.4k[1 issues](https://github.com/RyanNielson/prez/issues)MITPHPPHP &gt;=5.4.0

Since Jul 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/RyanNielson/prez)[ Packagist](https://packagist.org/packages/ryannielson/prez)[ Docs](https://github.com/RyanNielson/prez)[ RSS](/packages/ryannielson-prez/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

\#Prez

[![Build Status](https://camo.githubusercontent.com/6bccd0553e16b45e8f48c5a31da7efda716ecc610d699a5289237d2830dfc2ed/68747470733a2f2f7472617669732d63692e6f72672f5279616e4e69656c736f6e2f7072657a2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/RyanNielson/prez)[![Total Downloads](https://camo.githubusercontent.com/4116ba4d7b73fd361abcad1bd5d9667eda970180408e31c5dbdf578501094c2f/68747470733a2f2f706f7365722e707567782e6f72672f7279616e6e69656c736f6e2f7072657a2f646f776e6c6f6164732e737667)](https://packagist.org/packages/ryannielson/prez)[![Latest Stable Version](https://camo.githubusercontent.com/4d8d38cf229deca80454c7ee5b6cc86daeab5085420e6a4a9e3513c00628347d/68747470733a2f2f706f7365722e707567782e6f72672f7279616e6e69656c736f6e2f7072657a2f762f737461626c652e737667)](https://packagist.org/packages/ryannielson/prez)[![Latest Unstable Version](https://camo.githubusercontent.com/09fe4f063f9141bc8c0f24bfb53423edf37a0679d2367831aacfdab5c9298e22/68747470733a2f2f706f7365722e707567782e6f72672f7279616e6e69656c736f6e2f7072657a2f762f756e737461626c652e737667)](https://packagist.org/packages/ryannielson/prez)[![License](https://camo.githubusercontent.com/ddf0b23bbb54eb8d3b1d4237d638b054326f86cf0585a52e7650642c1eedaf13/68747470733a2f2f706f7365722e707567782e6f72672f7279616e6e69656c736f6e2f7072657a2f6c6963656e73652e737667)](https://packagist.org/packages/ryannielson/prez)

Simple presenters for your PHP or Laravel project.

Why Should I Use Presenters?
----------------------------

[](#why-should-i-use-presenters)

Imagine your application has a `User` model. With Prez, you'd create a matching `UserPresenter` class. This presenter wraps the model, dealing with only presentational concerns. This keeps any view related logic out of the model, while also helping you keep logic out of the view. In your view you can use the presenter in the same way you'd use the original model. Whenever you start thinking about creating a helper function or adding logic to your view, it might be worth moving it into a presenter.

Installation
------------

[](#installation)

Run the following Composer command in your terminal, or simply add `"ryannielson/prez": "~1.0.0"` to your composer.json file:

```
composer require ryannielson/prez:'~1.0.0'

```

Once complete, if using Laravel, you now have to add the the service provider to the providers array in `app/config/app.php`:

```
'RyanNielson\Prez\PrezServiceProvider'

```

Usage
-----

[](#usage)

### Creating Presenters

[](#creating-presenters)

Presenters inherit from `RyanNielson\Prez\Presenter`, and should be named for the model they present. In Laravel these should live in the `app/presenters` directory.

```
// app/presenters/UserPresenter.php
class UserPresenter extends RyanNielson\Prez\Presenter
{
}
```

### Laravel Commands

[](#laravel-commands)

Prez includes a command to automate the creation of Presenters.

To create a presenter called `UserPresenter` in `app/presenters`:

`php artisan prez:presenter User`

To create a presenter called `UserPresenter` in `app/custom`:

`php artisan prez:presenter User --path=app/custom`

### Accessing the Object in a Presenter

[](#accessing-the-object-in-a-presenter)

You can access the wrapped object in a presenter by using `$this->object`. This allows you get get any public property or call any public function on the object.

```
class UserPresenter extends RyanNielson\Prez\Presenter
{
    public function fullName()
    {
        return $this->object->firstName . ' ' . $this->object->lastName;
    }
}
```

You can also use the `presents` property on the presenter so that you can using a name other than `$this->object` to access the object. This makes the presenter code a bit more clear.

```
class UserPresenter extends RyanNielson\Prez\Presenter
{
    // This allows us to use $this->user instead of $this->object
    protected $presents = 'user';

    public function fullName()
    {
        return $this->user->firstName . ' ' . $this->user->lastName;
    }
}
```

### Getting a Presenter for an Object

[](#getting-a-presenter-for-an-object)

By default, Prez assumes that your presenter class uses your object's class name followed by presenter. For example, an object with the class `User` is assumed to have a corresponding `UserPresenter` class. The `presenter` helper method uses this assumption to find your presenter and return an instance of it.

```
$user = new User;
$userPresenter = presenter($user); // Returns an instance of UserPresenter
```

`presenter` also takes an optional class name if you want to force a specific presenter to be used.

```
$user = new User;
$userPresenter = presenter($user, 'AdminPresenter'); // Returns an instance of AdminPresenter
```

If you prefer not to use the helper function, you can explicitily pass your object when constructing a presenter.

```
$user = new User;
$userPresenter = new UserPresenter($user);
```

### Using a Presenter in a View

[](#using-a-presenter-in-a-view)

If you have a presenter object passed to your view, you can use your presenter like any other object. The following example assumes the usage of Laravel's blade template language.

```

{{ $userPresenter->fullName() }}
```

### Delegating to Object

[](#delegating-to-object)

If the presenter doesn't contain a property or method, the call is delegated to the wrapped object. This makes it so that if we want to access a field on the model, we don't have to write a function in the presenter.

```
class User
{
    public $name = 'Ryan';

    public function language()
    {
        return 'PHP';
    }
}

class UserPresenter extends RyanNielson\Prez\Presenter
{
}

$userPresenter = new UserPresenter(new User);

// Since no method or property exists on presenter, these flow to the object.
$userPresenter->name;
$userPresenter->language();
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Total

5

Last Release

3965d ago

Major Versions

1.0.3 → 2.0.02015-07-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/794694?v=4)[Ryan Nielson](/maintainers/RyanNielson)[@RyanNielson](https://github.com/RyanNielson)

---

Top Contributors

[![RyanNielson](https://avatars.githubusercontent.com/u/794694?v=4)](https://github.com/RyanNielson "RyanNielson (21 commits)")

---

Tags

laravelmodelviewpresenterdecorator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ryannielson-prez/health.svg)

```
[![Health](https://phpackages.com/badges/ryannielson-prez/health.svg)](https://phpackages.com/packages/ryannielson-prez)
```

###  Alternatives

[laracasts/presenter

Simple view presenters

8643.4M46](/packages/laracasts-presenter)[deefour/presenter

Presenters/Decorators for PHP Objects

122.5k](/packages/deefour-presenter)[guilhermegonzaga/presenter

Implementation for Laravel of the presenter design pattern.

47242.1k](/packages/guilhermegonzaga-presenter)[lewis/presenter

Simple view presenter library for Laravel.

174.7k](/packages/lewis-presenter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
