a2design/eloquent-presenter

This package is abandoned and no longer maintained. The author suggests using the faustbrian/eloquent-presenter package instead.

Model Presenters for Laravel

2.1.0 2016-11-21 09:54 UTC

README

Installation

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

$ composer require faustbrian/eloquent-presenter

Usage

Presenter

use BrianFaust\Presenter\BasePresenter;

class CommentPresenter extends BasePresenter
{
    public function getRoutePrefix()
    {
        return 'users.posts.comments';
    }

    public function getRouteParameters()
    {
        // The ID of the model will be automatically attached to this array at the end
        // [
        //     $model->post->user->id,
        //     $model->post->id,
        //     $model->id // "id" is what is specified in $this->getRouteKeyName()
        // ];

        return ['post.user.id', 'post.id'];
    }
}

Model

use BrianFaust\Presenter\HasViewPresenterTrait;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    use HasViewPresenterTrait;

    /**
     * Get the view presenter for the model.
     *
     * @return string
     */
    protected function getPresenter()
    {
        return UserPresenter::class;
    }
}

Security

If you discover a security vulnerability within this package, please send an e-mail to Brian Faust at hello@brianfaust.de. All security vulnerabilities will be promptly addressed.

License

The The MIT License (MIT). Please check the LICENSE file for more details.