Download the PHP package rickselby/laravel-auto-presenter-mapper without Composer
On this page you can find all versions of the php package rickselby/laravel-auto-presenter-mapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rickselby/laravel-auto-presenter-mapper
More information about rickselby/laravel-auto-presenter-mapper
Files in rickselby/laravel-auto-presenter-mapper
Package laravel-auto-presenter-mapper
Short Description Define presenters in a service provider rather than in the model
License MIT
Informations about the package laravel-auto-presenter-mapper
Laravel Auto Presenter Mapper
This is an extension to the excellent laravel-auto-presenter that allows you to define presenters in a service provider or on-the-fly, rather than directly on the model.
Compatibility Chart
Laravel Auto Presenter Mapper | laravel-auto-presenter |
---|---|
3.x | 7.x |
2.x | 6.x |
1.x | 5.x |
Installing
Require the project using Composer:
Laravel 5.5+ will auto-discover the package.
For Laravel 5.1-5.4, you should only add this service provider, not the original laravel-auto-presenter
service provider, as this one
extends it.
In your config/app.php
add this line to your 'providers' array...
... and this line to your 'facades' array.
Usage
Read the docs at github.com/laravel-auto-presenter/laravel-auto-presenter for the basic use cases.
With this package, instead of altering your models to implement HasPresenter
, you can define the presenters in a service
provider using the facade. For example:
This will work exactly how the laravel-auto-presenter works; any User
models passed to a view will be wrapped in UserPresenter
.
The map
function also takes an array:
If you wish to declare a mapping on-the-fly, or override a mapping in a specific instance, the facade can be called from anywhere:
Decoratable
To mimic the Decoratable
interface of the parent package, you can call decoratable
:
License
Laravel Auto Presenter Mapper is licensed under The MIT License (MIT).