PHP code example of datacreativa / laravel-presentable
1. Go to this page and download the library: Download datacreativa/laravel-presentable 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/ */
datacreativa / laravel-presentable example snippets
use App\Models\Presenters\UserPresenter;
use TheHiveTeam\Presentable\HasPresentable;
class User extends Model
{
use HasPresentable;
protected $presenter = UserPresenter::class;
}
namespace App\Models\Presenters;
use TheHiveTeam\Presentable\Presenter;
class UserPresenter extends Presenter
{
public function name()
{
return ucwords($this->model->name);
}
}
$user = (new User)->setAttribute('name', 'john doe');
$user->present()->name;
// John Doe
bash
php artisan make:presenter UserPresenter