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

ActiveLibrary

culturegr/presenter
===================

Eloquent Model Presenter for Laravel applications

v1.6.1(1y ago)141.4k1MITPHPCI failing

Since Nov 12Pushed 1y ago4 watchersCompare

[ Source](https://github.com/culturegr/presenter)[ Packagist](https://packagist.org/packages/culturegr/presenter)[ Docs](https://github.com/culturegr/presenter)[ RSS](/packages/culturegr-presenter/feed)WikiDiscussions main Synced 4d ago

READMEChangelog (10)Dependencies (5)Versions (13)Used By (0)

🏺 Presenter
===========

[](#-presenter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a819ba0e0d91b15e9326d14642985595b5fdcfbfe1b7a22a7a9364f59fce343b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63756c7475726567722f70726573656e7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/culturegr/presenter)[![Total Downloads](https://camo.githubusercontent.com/e2f20c73c9f62b4d2318ed9d5a424ebc01aeeb3468ff9b73aacd899c602ca82a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63756c7475726567722f70726573656e7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/culturegr/presenter)[![Github Actions](https://github.com/culturegr/presenter/actions/workflows/run-tests.yml/badge.svg)](https://github.com/culturegr/presenter/actions/workflows/run-tests.yml/badge.svg)

This package provides an easy way to create Presenters that can be used to [decorate](https://en.wikipedia.org/wiki/Decorator_pattern) an Eloquent Model. It is heavily inspired by [Hemp Presenter](https://github.com/davidhemphill/presenter) and [Laravel API Resources](https://laravel.com/docs/6.x/eloquent-resources), however it comes with some key differences:

- It provides an easy way to handle *paginated* models
- It does not focus solely in JSON API responses but it serves as a *general purpose* decorator that can be used anywhere in the project

TL;DR
-----

[](#tldr)

A **Decorator** is an object that wraps another object in order to add functionality to the wrapped object. It also delegates calls to methods not available on the decorator to the class being decorated. Decorators can be useful when you need to modify the functionality of a class without relying on inheritance. You can use it to add optional features to your objects like logging, access-control, and things of that sort. A **Presenter** is a type of decorator used to present an object to the view of an application, such as a Blade view, or an API response.

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

[](#installation)

Via [Composer](https://getcomposer.org):

```
$ composer require culturegr/presenter
```

In Laravel 5.5+, the package's service provider should be [auto-discovered](https://laravel.com/docs/5.7/packages#package-discovery), so you won't need to register it. If for some reason you need to register it manually you can do so by adding it to the providers array in `config/app.php`:

```
'providers' => [
    // ...
    CultureGr\Presenter\PresenterServiceProvider::class,
],
```

Usage
-----

[](#usage)

### Creating Presenter Classes

[](#creating-presenter-classes)

A Presenter class can be generated by running the `make:presenter` Artisan command:

```
php artisan make:presenter UserPresenter
```

This will generate an empty `Presenter` class inside of `app/Presenters`

### Customizing Presenter Classes

[](#customizing-presenter-classes)

Presenters are simple classes designed to encapsulate complex or repetitive view logic. For example, here is a simple `UserPresenter` class:

```
