PHP code example of analogue / presenter

1. Go to this page and download the library: Download analogue/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/ */

    

analogue / presenter example snippets


use Analogue\Presenter\Presenter;

class UserPresenter extends Presenter {

    public function fullName()
    {
        return $this->entity->first . ' ' . $this->entity->last;
    }

    public function accountAge()
    {
        return $this->entity->created_at->diffForHumans();
    }

}



use Analogue\ORM\Entity;
use Analogue\Presenter\Presentable;

class User extends Entity {

    use Presentable;
}



use Analogue\ORM\EntityMap;

// the UserPresenter class we created above
use App\Http\Presenters\UserPresenter;

class UserMap extends EntityMap
{
    public $presenter = UserPresenter::class;

    // ...
}

// in some controller
return view("user", ["user" => $user->present()]);

<h1>Hello, {{ $user->fullName() }}</h1>

// config/app.php
'providers' => [
    // ...
    Analogue\Presenter\PresentBladeServiceProvider::class,
]