A lot of times nowadays we are working with dozens of third-party packages and not all of those offer an easy way of replacing models used by them. This means it can become quite a task to extend or replace those if you would like to use something like a Presenter on these. This package tries to solve this issue by registering presenters like Laravel does with Policies to allow binding any Presenter to any model so you don't need to replace third-party models.
Require this package, with Composer, in the root directory of your project.
$ composer require artisanry/presenter-registrar
<?php
namespace App\Providers;
use Artisanry\PresenterRegistrar\PresenterRegistrarServiceProvider as ServiceProvider;
class PresenterServiceProvider extends ServiceProvider
{
protected $presenters = [
'App\User' => 'App\Presenters\UserPresenter',
'ThirdParty\Models\Model' => 'App\Presenters\ThirdPartyPresenter',
];
}
<?php
namespace App\Presenters;
use Artisanry\PresenterRegistrar\Presenter;
class UserPresenter extends Presenter
{
public function fullName()
{
return "{$this->model->firstName} {$this->model->lastName}";
}
}
{{ present($user)->fullName }}
$ phpunit
If you discover a security vulnerability within this package, please send an e-mail to hello@basecode.sh. All security vulnerabilities will be promptly addressed.
This project exists thanks to all the people who contribute.
Mozilla Public License Version 2.0 (MPL-2.0).