Simple View Presenter
The tool to separate logic of models and views., (*1)
Install
Require this package with composer, (*2)
composer require pustato/presenter
Usage
Implement Pustato\Presenter\Contracts\PresentableContract interface., (*3)
$name : null;
}
}
```
Make presenter class.
```php
$presentable->firstName.' '.$presentable->lastName,
// callable will be calculated at first call and cached.
'age' => function($presentable) {
return (int) $presentable
->birthDate
->diff(new \DateTime('now'))
->y;
}
];
}
}
```
Create presenter instance and use in views.
```php
$presenterInstance = new SomeModelPresenter($modelInstance)
```
```php
ID: = $presenterInstance->id ?></p>
, (*4)
Full name: = $presenterInstance->fullName ?>, (*5)
Age: = $presenterInstance->age ?>, (*6)