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

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

coburncodes/presenter
=====================

A presenter package for Laravel 5.5+ based off of the package by Laracasts

1.1.1(8y ago)021[1 issues](https://github.com/coreycoburn/presenter/issues)PHPPHP &gt;=7.1.3

Since Feb 23Pushed 8y ago1 watchersCompare

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

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

Laravel View Presenter
======================

[](#laravel-view-presenter)

The `coburncodes/presenter` package allows you to easily integrate view presenters to keep your models tidy.

This packaged is adopted from [`Laracasts' view presenter`](https://github.com/laracasts/Presenter). This package is compatible with Laravel v5.6+.

This package also provides extra conveniences like:

- Publish a config file to change the path of your view presenters
- Includes an artisan command to generate new view presenters for your models.

Install
-------

[](#install)

You can install the package via composer:

```
$ composer require coburncodes/presenter
```

### Config file

[](#config-file)

A config file can be published if you would like to change the default location of where the presenters are stored. By default, the view presenters are stored in the `Presenters` directory in the app root. Simply publish the config file by running:

```
$ php artisan vendor:publish
```

Find the presenter vendor

```
Provider: Coburncodes\Presenter\Providers\PresenterServiceProvider
```

Usage
-----

[](#usage)

### Add trait to model:

[](#add-trait-to-model)

To implement a view Presenter to a model add the `presentable` trait to your model.

```
use Coburncodes\Presenter\Presentable;

class User
{
    use Presentable;

    protected $fillable = [
        'first_name', 'last_name', 'email', 'password',
    ];
...
```

### Create the presenter using Artisan

[](#create-the-presenter-using-artisan)

An artisan command is included in the package to generate a view presenter for a model. Simply run:

```
$ php artisan presenter:generate
```

Follow the command prompts. Enter the name of the model that you want to create a presenter for as well as to create an initial method to present.

### Create the presenter manually

[](#create-the-presenter-manually)

You can manually create a presenter in your `Presenters` directory. The package uses the convention of `ModelPresenter` as the class name for each presenter. i.e. `UserPresenter`. See the following example:

```
