2017 © Pedro Peláez
 

library presenter

A presenter class for Laravel.

image

taylornetwork/presenter

A presenter class for Laravel.

  • Monday, February 20, 2017
  • by taylornetwork
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Presenter for Laravel

Adds another place to put logic for models. Instead of cluttering up models with logic to display/format data, add them to a presenter!, (*1)

This is a rewrite of laracasts/Presenter with some added functionality, commands, etc., (*2)

Install

Via Composer, (*3)

``` bash $ composer require taylornetwork/presenter, (*4)


## Setup Add the service provider to the providers array in `config/app.php` ``` php 'providers' => [ TaylorNetwork\Presenter\PresenterServiceProvider::class, ],

Publish Config

``` bash $ php artisan vendor:publish, (*5)


This will add `config/presenter.php` where you can define the namespace you want your presenter classes to be stored. ## Usage Create a presenter using the artisan command, for example a presenter for the User model. ``` bash $ php artisan make:presenter UserPresenter

This will create a presenter class you can add logic to that you don't want in the model or the view. Model attributes are accessible via $this->model, (*6)

``` php use TaylorNetwork\Presenter\Presenter;, (*7)

class UserPresenter extends Presenter { /** * Get the user's full name * * @return string */ public function fullName() { return $this->model->first_name . ' ' . $this->model->last_name; }, (*8)

/**
 * Get the time since the user signed up
 *
 * @return string
 */
public function userSince()
{
    return $this->model->created_at->diffForHumans();
}

}, (*9)


You will need to add the presentable trait and a `$presenter` property to your model ``` php use TaylorNetwork\Presenter\Presentable; use App\Presenters\UserPresenter; class User extends Model { use Presentable; /** * Presenter Class * * @var string */ protected $presenter = UserPresenter::class; // Code }

You can access the presenter with present(), (*10)

php <h1>{{ $user->present()->fullName }}, you signed up {{ $user->present()->userSince }}</h1>, (*11)

Credits

License

The MIT License (MIT). Please see License File for more information., (*12)

The Versions

20/02 2017

dev-master

9999999-dev

A presenter class for Laravel.

  Sources   Download

The Requires

 

by Sam Taylor

20/02 2017

1.1.0

1.1.0.0

A presenter class for Laravel.

  Sources   Download

The Requires

 

by Sam Taylor

16/11 2016

1.0.0

1.0.0.0

A presenter class for Laravel.

  Sources   Download

The Requires

 

by Sam Taylor