2017 © Pedro Peláez
 

library laravel-presenter

Laravel presenter package

image

haska/laravel-presenter

Laravel presenter package

  • Sunday, May 25, 2014
  • by haska
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel presenter package

Informations

Usage

The first step is to store your presenters somewhere - anywhere. These will be simple objects that do nothing more than format data, as required., (*1)

Here's an example of a presenter., (*2)

use Haska\Presenter\Presenter;

class UserPresenter extends Presenter {

    public function fullName()
    {
        return $this->first . ' ' . $this->last;
    }

    public function accountAge()
    {
        return $this->created_at->diffForHumans();
    }

}

Next, on your entity, pull in the Haska\Presenter\PresentableTrait trait, which will automatically instantiate your presenter class., (*3)

Here's an example - maybe a Laravel User model., (*4)

<?php

use Haska\Presenter\PresentableTrait;

class User extends \Eloquent {

    use PresentableTrait;

    protected $presenter = 'UserPresenter';

}

That's it! You're done. Now, within your view, you can do:, (*5)

    <h1>Hello, {{ $user->present()->fullName }}</h1>

Notice how the call to the present() method (which will return your new or cached presenter object) also provides the benefit of making it perfectly clear where you must go, should you need to modify how a full name is displayed on the page., (*6)

The Versions

25/05 2014

dev-master

9999999-dev

Laravel presenter package

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Haska

laravel view presenter