Download the PHP package analogue/presenter without Composer
On this page you can find all versions of the php package analogue/presenter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download analogue/presenter
More information about analogue/presenter
Files in analogue/presenter
Package presenter
Short Description Easy view presenters for Analogue ORM
License MIT
Homepage https://github.com/analogueorm/presenter
Informations about the package presenter
Analogue Presenter
Based heavily on Jeffrey Way's Easy View Presenters for Laravel
So you have those scenarios where a bit of logic needs to be performed before some data (likely from your entity) is displayed from the view.
- Should that logic be hard-coded into the view? No.
- Should we instead store the logic in the model? No again!
Instead, leverage view presenters. That's what they're for! This package provides one such implementation.
Install
Pull this package in through Composer.
Usage
The first step is to store your presenters somewhere - anywhere. These will be simple objects that do nothing more than format data, as required.
Here's an example of a presenter.
Next, on your entity, pull in the Analogue\Presenter\Presentable
trait.
Here's an example - maybe an Analogue User
entity.
Then, add a public $presentable
property to the relevant entity map:
That's it! You're done. Now, within your controller/view, you can do:
The Presenter will also pass through any calls to entity properties: e.g. $user->present()->first()
would return the $user->first
property - this is useful if you pass the presenter, rather than the entity, into your template.
Laravel Integration
There is also a PresentBladeServiceProvider
included for use with Laravel and the Blade templating language.
This adds a @presenteach
and @endpresenteach
directive, which allows you to easily iterate over the presenters for each entity in a collection: