2017 © Pedro Peláez
 

library presenter

Simple view presenters

image

erikgall/presenter

Simple view presenters

  • Saturday, January 9, 2016
  • by erikgall
  • Repository
  • 1 Watchers
  • 0 Stars
  • 31 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel Model/View Presenter (Laracasts)

So you have those scenarios where a bit of logic needs to be performed before some data (likely from your entity) is displayed from the view., (*1)

  • Should that logic be hard-coded into the view? No.
  • Should we instead store the logic in the model? No again!

Instead, leverage view presenters. That's what they're for! This package provides one such implementation., (*2)

Install

Pull this package in through Composer., (*3)

{
    "require": {
        "erikgall/presenter": "1.*"
    }
}

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., (*4)

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

use EGALL\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 Laracasts\Presenter\PresentableTrait trait, which will automatically instantiate your presenter class., (*6)

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

<?php

use EGALL\Presenter\PresentableTrait;

class User extends \Eloquent {

    use PresentableTrait;

    protected $presenter = 'UserPresenter';

}

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

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

The Versions

09/01 2016

dev-master

9999999-dev

Simple view presenters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Erik Galloway

30/06 2015

v1.0.0

1.0.0.0

Simple view presenters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Erik Galloway