2017 © Pedro Peláez
 

library laravel-components

Components for Laravel 5

image

willishq/laravel-components

Components for Laravel 5

  • Tuesday, September 30, 2014
  • by willishq
  • Repository
  • 0 Watchers
  • 3 Stars
  • 48 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Laravel components

Build Status, (*1)

These are components which I use frequently when creating and maintaining a Laravel project, and two traits which I keep copying from project to project., (*2)

Installation

Grab this package through Composer:, (*3)

{
    "require" {
        "willishq/laravel-components": "1.*"
    }
}

Traits

The two traits provided are the EventableTrait and the RetrievableTrait., (*4)

EventableTrait Usage

The EventableTrait is used in tandem with laracasts\commander package and enables you to raise and dispatch events directly on your objects (such as Eloquent models), along with firing events when the object is destroyed., (*5)

MyModel.php, (*6)

use Willishq\LaravelComponents\EventableTrait;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model {
    use EventableTrait;
    /**
     * Whether to dispatch remaining events when the object is tore down
     *
     * @var bool
     */
    protected $dispatchOnDestruct = true;
}
$model = new MyModel;

$model->raise(new ModelWasInstantiatedEvent($model));

if you left the model like this, the event would be fired automatically by the __destruct method, or you can call $model->dispatchEvents(); which would dispatch all remaining events., (*7)

RetrievableTrait Usage

The RetrievableTrait enables you to retrieve specific public keys from your objects. It provides you with two methods, retrieveOnly and retrieveExcept, (*8)

use Willishq\LaravelComponents\RetrievableTrait;
class Book {
    use RetrievableTrait;

    public $title;
    public $author;
    public $publish_date;
    public $blurb;

    public function __construct($title, $author, $publish_date, $blurb)
    {
        $this->title = $title;
        $this->author = $author;
        $this->publish_date = $publish_date;
        $this->blurb = $blurb;
    }
}
$book = new Book('My Amazing Book', 'Andrew Willis', '19/04/2020', 'Andrew was a normal person from Sunderland. you\'ll never believe what happened next.');

$fields = $book->retrieveOnly('title', 'author');
// ['title' => 'My Amazing Book', 'author' => 'Andrew Willis']

$fields = $book->retrieveExcept('blurb');
// ['title' => 'My Amazing Book', 'author' => 'Andrew Willis', '19/04/2020']

I have found this useful when dealing with DTO's., (*9)

Packages

Please be sure to add the following to your config/app.php file to use the packages!, (*10)

Service Providers:

        // Laravel DebugBar
        'Barryvdh\Debugbar\ServiceProvider',
        // Laracasts Commander package
        'Laracasts\Commander\CommanderServiceProvider',
        // Laracasts Flash package
        'Laracasts\Flash\FlashServiceProvider',
        // Laravel 5 requires you to include the HTML package yourself
        'Illuminate\Html\HtmlServiceProvider',

Facades:

        'Debugbar'  => 'Barryvdh\Debugbar\Facade',
        'Form'      => 'Illuminate\Html\FormFacade',
        'Flash'     => 'Laracasts\Flash\Flash',

Other packages included are: laracasts/presenter and league/fractal., (*11)

Documentation for all of the packages included can be found here:, (*12)

For development and testing, I suggest you use codeception/codeception, laracasts/testdummy and fzaninotto/faker - github.com/laracasts/TestDummy - github.com/fzaninotto/faker - github.com/codeception/codeception, (*13)

The Versions

30/09 2014

dev-master

9999999-dev

Components for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrew Willis

laravel laravel5 setup

30/09 2014
25/09 2014

dev-develop

dev-develop

Components for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrew Willis

laravel laravel5 setup

25/09 2014
25/09 2014