PHPackages                             hossam-tarek/laravel-presenter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hossam-tarek/laravel-presenter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hossam-tarek/laravel-presenter
==============================

Introducing a Laravel Implementation of the Presenter Pattern

v1.0.1(2y ago)1848MITPHPPHP ^7.2|^8.0

Since Aug 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Hossam-Tarek/laravel-presenter)[ Packagist](https://packagist.org/packages/hossam-tarek/laravel-presenter)[ RSS](/packages/hossam-tarek-laravel-presenter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Laravel Presenter Package
=========================

[](#laravel-presenter-package)

The Laravel Presenter Package is an elegant solution that seamlessly integrates the Presenter design pattern into your Laravel applications. This package assists in improving the maintainability and readability of your codebase by separating data formatting and manipulation logic from your models and views.

Content
-------

[](#content)

- [Benefits of the Presenter Pattern](#benefits-of-the-presenter-pattern)
- [Installation](#installation)
- [Creating a new Presenter](#creating-a-new-presenter)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
- [Credits](#credits)

Benefits of the Presenter Pattern
---------------------------------

[](#benefits-of-the-presenter-pattern)

The Presenter pattern offers several key benefits:

- **Code Separation:** The presenter separates data manipulation logic from your models, preventing your models from becoming cluttered with presentation-related code.
- **Cleaner Views:** By formatting data in presenters, your views remain focused on displaying data rather than implementing logic.
- **Reusability:** Presenters enable you to reuse the same formatting logic across multiple views, ensuring consistent data representation.
- **Maintainability:** Isolating formatting logic in presenters simplifies future changes, making code maintenance smoother.

Installation
------------

[](#installation)

You can easily install the Laravel Presenter Package via Composer by executing the following command:

```
composer require hossam-tarek/laravel-presenter
```

If you are using a Laravel version before 5.5, make sure to include the `LaravelPresenterServiceProvider` in your `config/app.php` file.

```
'providers' => [
    // Other providers
    HossamTarek\LaravelPresenter\LaravelPresenterServiceProvider::class,
],
```

Creating a new Presenter
------------------------

[](#creating-a-new-presenter)

- To create a new presenter, you can use the following Artisan command:

    ```
    php artisan make:presenter {className}
    ```

    Replace `{className}` with the desired name for your presenter. This command will generate a new presenter class under the `app/Presenters` directory.
- Associating the Presenter by importing the `HasPresenter` trait into your model and set the `$presenterName` variable as follows:

    ```
    use HossamTarek\LaravelPresenter\Traits\HasPresenter;
    use App\Presenters\OrderPresenter;

    class User extends Model
    {
        use HasPresenter;

        protected static $presenterName = UserPresenter::class;
    }
    ```

Usage
-----

[](#usage)

Instead of duplicating the following logic all over your views and violating the SOLID principles:

```
@if(empty($user_website_url))
    {{ $user->first_name }} {{ $user->last_name }}
@else

            {{ $user->first_name }} {{ $user->last_name }}

@endif
```

Use the command `php artisan make:presenter UserPresenter` to create a new `UserPresenter` and place the presentation logic in it.

Then attach the `UserPresenter` to the `User` model and use the `HasPresenter` trait.

```
class User extends Model
{
    use \HossamTarek\LaravelPresenter\Traits\HasPresenter;

    protected static $presenterName = UserPresenter::class;
}
```

Now use the `UserPresenter` to separate the presentation logic from views and model.

```
class UserPresenter extendsPresenter
{
    protected $model;

    public function formattedName($class = '')
    {
        if (empty($user->website_url)) {
            return "{$user->first_name} {$user->last_name}"
        }

        return
                {$user->first_name} {$user->last_name}

        HTML;
    }
}
```

Now you are ready to unleash the power of the Presenter Pattern.

In your views:

```
{!! $user->formattedName() !!}
```

If the function has no args use the shorter syntax (snake case) without parentheses as if it was a property of the object.

```
{!! $user->formatted_name !!}
```

If you want to add classes to the `p` tag for more customization.

```
{!! $user->formattedName("mx-2 my-3") !!}
```

Contributing
------------

[](#contributing)

Your contributions are highly valued as we work together to enhance the Laravel Presenter Package. Feel free to report issues and suggest enhancements to unlock the power of clean code, organization, and improved maintainability.

License
-------

[](#license)

The Laravel Presenter Package is an open-source software licensed under the [MIT](./LICENSE) license.

Credits
-------

[](#credits)

The Laravel Presenter Package was crafted and is maintained by [Hossam Tarek](https://github.com/Hossam-Tarek).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

2

Last Release

998d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0069b349bb5cd4a00b4f85f8faa384b21514243d41d78784178cc149f882c8ca?d=identicon)[Hossam Tarek](/maintainers/Hossam%20Tarek)

---

Top Contributors

[![Hossam-Tarek](https://avatars.githubusercontent.com/u/23726675?v=4)](https://github.com/Hossam-Tarek "Hossam-Tarek (12 commits)")

### Embed Badge

![Health badge](/badges/hossam-tarek-laravel-presenter/health.svg)

```
[![Health](https://phpackages.com/badges/hossam-tarek-laravel-presenter/health.svg)](https://phpackages.com/packages/hossam-tarek-laravel-presenter)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
