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

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

daniiltserin/presenter
======================

Simple view presenter library for Laravel.

v1.0.3(9y ago)016MITPHPPHP &gt;=5.5.9

Since Sep 7Pushed 9y agoCompare

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

READMEChangelogDependenciesVersions (13)Used By (0)

A view presenter is an incredibly useful way of decorating objects bound to your views. This allows you to perform view related logic in a sensible place instead of placing it directly in your views, or worse, your models.

There are [several](https://github.com/laravel-auto-presenter/laravel-auto-presenter) [other](https://github.com/laracasts/Presenter) [libraries](https://github.com/robclancy/presenter) out their that provide similar functionality. This package is merely my preferred implementation as everything is configured in isolation to the object being decorated.

### Install

[](#install)

You can install this package using Composer:

```
$ composer require daniiltserin/presenter

```

Or in your `composer.json`:

```
{
    "require": {
        "daniiltserin/presenter": "*"
    }
}
```

Once you've run `composer update` you'll need to register the **service provider** in your `config/app.php` file.

```
'providers' => [
    Daniiltserin\Presenter\PresenterServiceProvider::class
]
```

### Usage

[](#usage)

#### Configuring Presenters

[](#configuring-presenters)

There's several ways to configure your presenters. First, you can utilize the configuration file, which can be published using the following command:

```
$ php artisan vendor:publish --provider="Daniiltserin\Presenter\PresenterServiceProvider"

```

There are no presenters configured by default. The published file merely contains an explanation on how to configure your presenters. You must provide an array of key/value pairs linking your object to its presenter.

```
return [

    App\User::class => App\Presenters\UserPresenter::class,
    App\Post::class => App\Presenters\PostPresenter::class

];
```

If you'd prefer you can set an array of presenters directly on the decorator. You might choose do to this from a service provider.

```
$this->app['decorator']->setBindings([
    \App\User::class => \App\Presenters\UserPresenter::class,
    \App\Post::class => \App\Presenters\PostPresenter::class
]);
```

Lastly, you can configure presenters one at a time using the `register` method, again, from within a provider.

```
$this->app['decorator']->register(\App\User::class, \App\Presenters\UserPresenter::class);
```

#### Creating Presenters

[](#creating-presenters)

A presenter should extend from `Daniiltserin\Presenter\AbstractPresenter`, however, it is *NOT* required, but highly recommended, as you'll have access to several methods and magic methods that provide some useful functionality.

I like to keep my presenters within a `Presenters` folder, however, you may organize things in whichever way you prefer.

```
namespace App\Presenters;

use Daniiltserin\Presenter\AbstractPresenter;

class UserPresenter extends AbstractPresenter
{

}
```

If you wish to inject dependencies the only requirements are that you name a parameter `$object` so that Laravel can correctly inject the bound object and that you call the parent constructor.

```
namespace App\Presenters;

use App\SomeNamespace\SomeClass;
use Daniiltserin\Presenter\AbstractPresenter;

class UserPresenter extends AbstractPresenter
{
    protected $class;

    public function __construct($object, SomeClass $class)
    {
        $this->class = $class;

        parent::__construct($object);
    }
}
```

Your presenter can then define methods to perform logic that can be used in your views.

```
public function prettySlug()
{
    return '/'.ltrim($this->slug, '/');
}
```

You can reference properties on the wrapped object directly (as above), or by using the `$object` property.

```
public function prettySlug()
{
    return '/'.ltrim($this->object->slug, '/');
}
```

#### From Within Views

[](#from-within-views)

Now that you've configured your presenters and created them, you just need to use them from within your views. It's a simple matter of calling the method or property as you define it.

```
{{ $post->prettySlug }}

Or:

{{ $post->prettySlug() }}
```

You can also still access you relations and other model attributes.

```
{{ $post->title }}

@foreach($post->comments as $comment)
    ...
@endforeach
```

### Enjoy

[](#enjoy)

That's about all there is to it.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 92.9% 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 ~51 days

Recently: every ~137 days

Total

12

Last Release

3336d ago

Major Versions

v0.1.7 → v1.0.02015-09-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/9622b376ba67c3bc9dd78ed21297a8ec903246242b3e583910329d83cffa266c?d=identicon)[daniiltserin](/maintainers/daniiltserin)

---

Top Contributors

[![jasonlewis](https://avatars.githubusercontent.com/u/829059?v=4)](https://github.com/jasonlewis "jasonlewis (13 commits)")[![curiousworx](https://avatars.githubusercontent.com/u/3485750?v=4)](https://github.com/curiousworx "curiousworx (1 commits)")

---

Tags

laravelviewpresenterdecorator

### Embed Badge

![Health badge](/badges/daniiltserin-presenter/health.svg)

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

###  Alternatives

[laracasts/presenter

Simple view presenters

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

Decorate your objects using presenters. Primarily to keep presentation logic out of your models.

3451.1M8](/packages/robclancy-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)[deefour/presenter

Presenters/Decorators for PHP Objects

122.5k](/packages/deefour-presenter)

PHPackages © 2026

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