1. Go to this page and download the library: Download brandonshar/presenters 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/ */
brandonshar / presenters example snippets
use brandonshar\Presenter;
class VehicleOnCraigslistPresenter extends Presenter
{
protected $vehicle;
protected $craigslistAd;
public function __construct(Vehicle $vehicle, CraigslistAd $craigslistAd)
{
$this->vehicle = $vehicle;
$this->craigslistAd = $craigslistAd;
}
}
$presenter = VehicleOnCraigslistPresenter::present($vehicle, $vehicle->craiglistAd);
class VehicleOnCraigslistPresenter extends Presenter
{
//...
public function getVehicleTitleAttribute()
{
return "{$this->vehicle->year} {$this->vehicle->make} {$this->vehicle->model}";
}
public function getCachedAtAttribute($currentValue)
{
return DateTime::createFromFormat('Y-m-d', $currentValue)->format('l, M jS');
}
//...
}
$presenter->vehicleTitle;
//or if you prefer
$presenter->vehicle_title;