datacreativa/
laravel-presentable
g4t.io

View Presenter Classes for Eloquent Models

23 views 72 stars by Paul Redmond

Create presenters for Eloquent Models

README from datacreativa/laravel-presentable Open on GitHub →

Laravel Presentable

Total Downloads GitHub Actions

Banner

This package allows the information to be presented in a different way by means of methods that can be defined in the model's presenter class.

Installation

You can install the package via composer:

Laravel Version
6, 7, 8 1.0.0
9 1.1.0
10 1.2.0
11 1.3.0
12 1.4.0
13 1.5.0
composer require datacreativa/laravel-presentable

Usage

Use the HasPresentable trait in any Eloquent Model, you must also add the $presenter property.


use App\Models\Presenters\UserPresenter;
use TheHiveTeam\Presentable\HasPresentable;

class User extends Model
{
    use HasPresentable;

    protected $presenter = UserPresenter::class;
}

You can generate a class presenter with this command:

php artisan make:presenter UserPresenter

In this class you can define any method, for example:

namespace App\Models\Presenters;

use TheHiveTeam\Presentable\Presenter;

class UserPresenter extends Presenter
{
    public function name()
    {
        return ucwords($this->model->name);
    }
}

Now you have available the present() method in Eloquent Model.

$user = (new User)->setAttribute('name', 'john doe');
$user->present()->name;
// John Doe

Enjoy it!

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

More from the ecosystem

durable-workflow/
workflow
g4t.io
9 1,292

Durable Workflow: Long-Running Workflows for Laravel

Embedded durable workflow runtime and orchestration engine for Laravel applications.

durable-workflow/workflow via Laravel News
packstub/
session-replay
g4t.io
14 52

Session Replay for Laravel: Self-Hosted Browser Recordings

Session replay for Laravel: record what a person did in the browser with rrweb, keep the recording on your own disk and database, and watch it behind a gate you define — masked inputs by default, errors, failed Livewire requests and web vitals marked on the timeline, a link to the replay in every log line. packstub/filament-session-replay adds the sessions to a Filament panel.

packstub/session-replay via Laravel News
cyberwizard-dev/
schedule-catchup
g4t.io
17

Replay Missed Laravel Scheduled Tasks With Schedule Catchup

Schedule Catchup replays missed Laravel scheduled tasks after downtime, with opt-in recovery, bounded retries, and access to the original scheduled date.

cyberwizard-dev/schedule-catchup via Laravel News