1. Go to this page and download the library: Download willishq/laravel-components library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
willishq / laravel-components example snippets
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));
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']