PHPackages                             ryanwinchester/laravel-auto-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. [Database &amp; ORM](/categories/database)
4. /
5. ryanwinchester/laravel-auto-presenter

ActiveLibrary[Database &amp; ORM](/categories/database)

ryanwinchester/laravel-auto-presenter
=====================================

A system for auto-decorating models with presenter objects.

v4.4.0(9y ago)11.5k1MITPHPPHP &gt;=5.5.9

Since Sep 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ryanwinchester/laravel-auto-presenter)[ Packagist](https://packagist.org/packages/ryanwinchester/laravel-auto-presenter)[ RSS](/packages/ryanwinchester-laravel-auto-presenter/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (9)Versions (26)Used By (1)

Laravel Auto Presenter 4
========================

[](#laravel-auto-presenter-4)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/f5975f9f5bd1096b11bfaae339ca42d74f1952a156888da9773b77ffc791d949/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7279616e77696e636865737465722f6c61726176656c2d6175746f2d70726573656e7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwinchester/laravel-auto-presenter)[![Latest Version](https://camo.githubusercontent.com/bb15cddf7b5edb5a9b76fb6f67c3c1c6595b1141a3eb8f7e0513ef44d3d7c269/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7279616e77696e636865737465722f6c61726176656c2d6175746f2d70726573656e7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/ryanwinchester/laravel-auto-presenter)

This package automatically decorates objects bound to views during the view render process.

Features
--------

[](#features)

- Automatically decorate objects bound to views
- Automatically decorate objects within paginator instances
- Automatically decorate objects within arrays and collections

Installing
----------

[](#installing)

Either [PHP](https://php.net) 5.5+ or [HHVM](http://hhvm.com) 3.6+ are required.

To get the latest version of Laravel Auto Presenter, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require ryanwinchester/laravel-auto-presenter
```

Instead, you may of course manually update your require block and run `composer update` if you so choose:

```
{
    "require": {
        "ryanwinchester/laravel-auto-presenter": "^4.0"
    }
}
```

Then, in your `config/app.php` add this line to your 'providers' array.

```
'McCool\LaravelAutoPresenter\AutoPresenterServiceProvider',
```

Usage
-----

[](#usage)

To show how it's used, we'll pretend that we have an Eloquent Post model. It doesn't have to be Eloquent, it could be any kind of class. But, this is a normal situation. The Post model represents a blog post.

I'm using really basic code examples here, so just focus on how the auto-presenter is used and ignore the rest.

```
use Example\Accounts\User;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $table = 'posts';
    protected $fillable = ['author_id', 'title', 'content', 'published_at'];

    public function author()
    {
        return $this->belongsTo(User::class, 'author_id');
    }
}
```

Also, we'll need a controller..

```
use Example\Accounts\Post;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;

class PostsController extends Controller
{
    public function getIndex()
    {
        $posts = Post::all();
        return View::make('posts.index', compact('posts'));
    }
}
```

and a view...

```
@foreach($posts as $post)
    {{ $post->title }} - {{ $post->published_at }}
@endforeach
```

In this example the published\_at attribute is likely to be in the format: "Y-m-d H:i:s" or "2013-08-10 10:20:13". In the real world this is not what we want in our view. So, let's make a presenter that lets us change how the data from the Post class is rendered within the view.

```
use Carbon\Carbon;
use Example\Accounts\Post;
use McCool\LaravelAutoPresenter\BasePresenter;

class PostPresenter extends BasePresenter
{
    public function __construct(Post $resource)
    {
        $this->wrappedObject = $resource;
    }

    public function published_at()
    {
        $published = $this->wrappedObject->published_at;

        return Carbon::createFromFormat('Y-m-d H:i:s', $published)
            ->toFormattedDateString();
    }
}
```

Here, the automatic presenter decorator is injecting the Post model that is to be decorated. **Please be aware that the constructor parameter should always be named `$resource` to allow Laravel's IoC container to correctly resolve the dependency.**

We need the post class to implement the interface.

```
use Example\Accounts\User;
use Example\Blog\PostPresenter;
use McCool\LaravelAutoPresenter\HasPresenter;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements HasPresenter
{
    protected $table = 'posts';
    protected $fillable = ['author_id', 'title', 'content', 'published_at'];

    public function author()
    {
        return $this->belongsTo(User::class, 'author_id');
    }

    public function getPresenterClass()
    {
        return PostPresenter::class;
    }
}
```

Now, with no additional changes our view will show the date in the desired format.

Troubleshooting
---------------

[](#troubleshooting)

If an object isn't being decorated correctly in the view then there's a good chance that it's simply not in existence when the view begins to render. For example, lazily-loaded relationships won't be decorated. You can fix this by eager-loading them instead. Auth::user() will never be decorated. I prefer to bind $currentUser to my views, anyway.

Security
--------

[](#security)

If you discover a security vulnerability within this package, please send an e-mail to Graham Campbell at . All security vulnerabilities will be promptly addressed.

License
-------

[](#license)

Laravel Auto Presenter is licensed under [The MIT License (MIT)](LICENSE).

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 79.7% 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 ~44 days

Recently: every ~76 days

Total

25

Last Release

3616d ago

Major Versions

1.1.0 → 2.0.02014-06-06

1.2.0 → 2.2.02014-08-25

2.2.1 → 3.0.0-beta32014-10-25

2.2.2 → 3.0.02015-02-04

3.1.1 → 4.0.02015-06-26

PHP version history (5 changes)1.0.0PHP &gt;=5.3.0

1.2.0PHP &gt;=5.3.3

2.2.0PHP &gt;=5.4.0

3.0.0-beta3PHP &gt;=5.5.0

4.0.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/f839bc1a48d9699534fdfd618ad477afe371e9ce70c76885a5cb851895ab7289?d=identicon)[ryanwinchester](/maintainers/ryanwinchester)

---

Top Contributors

[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (161 commits)")[![kirkbushell](https://avatars.githubusercontent.com/u/65171?v=4)](https://github.com/kirkbushell "kirkbushell (23 commits)")[![ryanwinchester](https://avatars.githubusercontent.com/u/2897340?v=4)](https://github.com/ryanwinchester "ryanwinchester (4 commits)")[![rquadling](https://avatars.githubusercontent.com/u/12801?v=4)](https://github.com/rquadling "rquadling (2 commits)")[![rtablada](https://avatars.githubusercontent.com/u/2532004?v=4)](https://github.com/rtablada "rtablada (2 commits)")[![mrsimonbennett](https://avatars.githubusercontent.com/u/1471305?v=4)](https://github.com/mrsimonbennett "mrsimonbennett (2 commits)")[![stidges](https://avatars.githubusercontent.com/u/4399967?v=4)](https://github.com/stidges "stidges (1 commits)")[![bl4ck-bird](https://avatars.githubusercontent.com/u/3314410?v=4)](https://github.com/bl4ck-bird "bl4ck-bird (1 commits)")[![webcraft](https://avatars.githubusercontent.com/u/56675?v=4)](https://github.com/webcraft "webcraft (1 commits)")[![bonroyage](https://avatars.githubusercontent.com/u/4411748?v=4)](https://github.com/bonroyage "bonroyage (1 commits)")[![hardevine](https://avatars.githubusercontent.com/u/1171618?v=4)](https://github.com/hardevine "hardevine (1 commits)")[![hendore](https://avatars.githubusercontent.com/u/1441228?v=4)](https://github.com/hendore "hendore (1 commits)")[![jamierumbelow](https://avatars.githubusercontent.com/u/49284?v=4)](https://github.com/jamierumbelow "jamierumbelow (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")

---

Tags

laraveleloquentpresenter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ryanwinchester-laravel-auto-presenter/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8405.5M96](/packages/laravel-doctrine-orm)[illuminate/database

The Illuminate Database package.

2.8k54.1M11.2k](/packages/illuminate-database)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9772.3M122](/packages/roots-acorn)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M88](/packages/mongodb-laravel-mongodb)

PHPackages © 2026

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