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

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

ramiawadallah/presenter
=======================

Simple view presenter library for Laravel.

1.8.x-dev(5y ago)0842MITPHPPHP ^7.2.5CI failing

Since Mar 10Pushed 2y ago1 watchersCompare

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

READMEChangelogDependencies (7)Versions (5)Used By (2)

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 ramiawadallah/presenter

```

Or in your `composer.json`:

```
{
    "require": {
        "ramiawadallah/presenter": "0.1.*"
    }
}
```

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

```
'providers' => [
    Ramiawadallah\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="Ramiawadallah\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 `Ramiawadallah\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 Ramiawadallah\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 Ramiawadallah\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

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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 ~556 days

Total

4

Last Release

1001d ago

PHP version history (3 changes)1.1.x-devPHP ^7.1.3

1.7.x-devPHP ^7.2.5

1.8.1.x-devPHP ^7.2|^8.0|^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8626791?v=4)[Rami Awadallah](/maintainers/ramiawadallah)[@ramiawadallah](https://github.com/ramiawadallah)

---

Top Contributors

[![ramiawadallah](https://avatars.githubusercontent.com/u/8626791?v=4)](https://github.com/ramiawadallah "ramiawadallah (17 commits)")

---

Tags

laravelviewpresenterdecorator

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[laracasts/presenter

Simple view presenters

8653.6M47](/packages/laracasts-presenter)[guilhermegonzaga/presenter

Implementation for Laravel of the presenter design pattern.

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

Simple view presenter library for Laravel.

164.7k](/packages/lewis-presenter)[ublabs/blade-simple-icons

A package to easily make use of Simple Icons in your Laravel Blade views.

1958.8k](/packages/ublabs-blade-simple-icons)[deefour/presenter

Presenters/Decorators for PHP Objects

122.5k](/packages/deefour-presenter)

PHPackages © 2026

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