Skip to content
This repository has been archived by the owner on Jan 3, 2020. It is now read-only.

faustbrian/laravel-presenter-registrar

Repository files navigation

Laravel Presenter Registrar

Build Status PHP from Packagist Latest Version License

The Problem

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.

Installation

Requirements

Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/presenter-registrar

Usage

Register presenters via PresenterServiceProvider

<?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',
    ];
}

Create the previously registered presenter

<?php

namespace App\Presenters;

use Artisanry\PresenterRegistrar\Presenter;

class UserPresenter extends Presenter
{
    public function fullName()
    {
        return "{$this->model->firstName} {$this->model->lastName}";
    }
}

Use presenter from anywhere (usually inside a view)

{{ present($user)->fullName }}

Testing

$ phpunit

Security

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.

Credits

This project exists thanks to all the people who contribute.

License

Mozilla Public License Version 2.0 (MPL-2.0).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages