Download the PHP package ryanwinchester/laravel-auto-presenter without Composer
On this page you can find all versions of the php package ryanwinchester/laravel-auto-presenter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ryanwinchester/laravel-auto-presenter
More information about ryanwinchester/laravel-auto-presenter
Files in ryanwinchester/laravel-auto-presenter
Package laravel-auto-presenter
Short Description A system for auto-decorating models with presenter objects.
License MIT
Informations about the package laravel-auto-presenter
Laravel Auto Presenter 4
This package automatically decorates objects bound to views during the view render process.
Features
- Automatically decorate objects bound to views
- Automatically decorate objects within paginator instances
- Automatically decorate objects within arrays and collections
Installing
Either PHP 5.5+ or HHVM 3.6+ are required.
To get the latest version of Laravel Auto Presenter, simply require the project using Composer:
Instead, you may of course manually update your require block and run composer update
if you so choose:
Then, in your config/app.php
add this line to your 'providers' array.
Usage
To show how it's used, we'll pretend that we have an Eloquent Post model. It doesn't have to be Eloquent, it could be any kind of class. But, this is a normal situation. The Post model represents a blog post.
I'm using really basic code examples here, so just focus on how the auto-presenter is used and ignore the rest.
Also, we'll need a controller..
and a view...
In this example the published_at attribute is likely to be in the format: "Y-m-d H:i:s" or "2013-08-10 10:20:13". In the real world this is not what we want in our view. So, let's make a presenter that lets us change how the data from the Post class is rendered within the view.
Here, the automatic presenter decorator is injecting the Post model that is to be decorated. Please be aware that the constructor parameter should always be named $resource
to allow Laravel's IoC container to correctly resolve the dependency.
We need the post class to implement the interface.
Now, with no additional changes our view will show the date in the desired format.
Troubleshooting
If an object isn't being decorated correctly in the view then there's a good chance that it's simply not in existence when the view begins to render. For example, lazily-loaded relationships won't be decorated. You can fix this by eager-loading them instead. Auth::user() will never be decorated. I prefer to bind $currentUser to my views, anyway.
Security
If you discover a security vulnerability within this package, please send an e-mail to Graham Campbell at [email protected]. All security vulnerabilities will be promptly addressed.
License
Laravel Auto Presenter is licensed under The MIT License (MIT).
All versions of laravel-auto-presenter with dependencies
illuminate/container Version 5.1.*|5.2.*|5.3.*
illuminate/contracts Version 5.1.*|5.2.*|5.3.*
illuminate/events Version 5.1.*|5.2.*|5.3.*
illuminate/pagination Version 5.1.*|5.2.*|5.3.*
illuminate/support Version 5.1.*|5.2.*|5.3.*
illuminate/view Version 5.1.*|5.2.*|5.3.*