1. Go to this page and download the library: Download hemp/presenter 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/ */
namespace App\Presenters;
use Hemp\Presenter\Presenter;
class ApiPresenter extends Presenter
{
public function createdDate()
{
return $this->created_at->format('n/j/Y');
}
public function getFullNameAttribute()
{
return trim($this->first_name . ' ' . $this->last_name);
}
}
$presentedUser->full_name;
$presentedUser->createdAt();
class ApiPresenter extends Presenter
{
public $snakeCase = false;
}
use Hemp\Presenter\Presentable;
class User extends \Illuminate\Database\Eloquent\Model
{
use Presentable;
}
$presentedUser = User::first()->present(ApiPresenter::class);
use Hemp\Presenter\Presentable;
class User extends \Illuminate\Database\Eloquent\Model
{
use Presentable;
public $defaultPresenter = App\Presenters\ApiPresenter::class;
}
$presentedUser = User::first()->present();