2017 © Pedro Peláez
 

library laravel-auto-presenter-mapper

Define presenters in a service provider rather than in the model

image

rickselby/laravel-auto-presenter-mapper

Define presenters in a service provider rather than in the model

  • Monday, May 14, 2018
  • by rickselby
  • Repository
  • 1 Watchers
  • 4 Stars
  • 342 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 40 % Grown

The README.md

Laravel Auto Presenter Mapper

Software License Packagist Version, (*1)

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., (*2)

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:, (*3)

$ composer require rickselby/laravel-auto-presenter-mapper

Laravel 5.5+ will auto-discover the package., (*4)

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., (*5)

In your config/app.php add this line to your 'providers' array..., (*6)

RickSelby\LaravelAutoPresenterMapper\AutoPresenterMapperServiceProvider::class,

... and this line to your 'facades' array., (*7)

'Presenters' => \RickSelby\LaravelAutoPresenterMapper\Facades\AutoPresenterMapperFacade::class,

Usage

Read the docs at github.com/laravel-auto-presenter/laravel-auto-presenter for the basic use cases., (*8)

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:, (*9)

public function register()
{
    \Presenters::map(User::class, UserPresenter::class);
}

This will work exactly how the laravel-auto-presenter works; any User models passed to a view will be wrapped in UserPresenter., (*10)

The map function also takes an array:, (*11)

public function register()
{
    \Presenters::map([
        User::class => UserPresenter::class,
        ...
    ]);
}

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:, (*12)

public function show(User $user)
{
    \Presenters::map(User::class, UserJSONPresenter::class);
    ...
}

Decoratable

To mimic the Decoratable interface of the parent package, you can call decoratable:, (*13)

public function register()
{
    \Presenters::decorate(User::class);
    \Presenters::decorate([
        User::class,
        ...
    ]);
    ...
}

License

Laravel Auto Presenter Mapper is licensed under The MIT License (MIT)., (*14)

The Versions

14/05 2018

2.x-dev

2.9999999.9999999.9999999-dev

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

14/05 2018

v2.2.1

2.2.1.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

14/05 2018

dev-master

9999999-dev

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

14/05 2018

v3.0.1

3.0.1.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

14/05 2018

dev-decorating-fix

dev-decorating-fix

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

12/05 2018

v3.0

3.0.0.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

12/05 2018

v3.x-dev

3.9999999.9999999.9999999-dev

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

12/05 2018

v2.2

2.2.0.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

27/10 2017

v2.1

2.1.0.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

29/09 2017

v2.0.1

2.0.1.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

23/09 2017

v2.0

2.0.0.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

06/05 2017

v1.1

1.1.0.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

06/05 2017

1.x-dev

1.9999999.9999999.9999999-dev

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires

03/03 2017

v1.0

1.0.0.0

Define presenters in a service provider rather than in the model

  Sources   Download

MIT

The Requires

 

The Development Requires