- What does coderflexx/laravel-presenter do and when should I use it?
- It implements the presenter (decorator) pattern for Laravel: you wrap an Eloquent model or DTO in a presenter class that exposes display-ready attributes, so formatting logic lives in one reusable place instead of in Blade templates or model accessors. Use it when your views or responses keep accumulating date formatting, money formatting, status labels and similar presentation rules. It is additive and does not replace the container, router or ORM.
- How do I install coderflexx/laravel-presenter in a Laravel app?
- Install it with composer require coderflexx/laravel-presenter. The service provider is auto-discovered, so you do not need to edit config/app.php, and there is no database, queue or cache surface to set up. After installing, scaffold your first presenter with the make:presenter command and wire it into a single controller or Blade view before rolling it out further. Pin the version in composer.json and commit the lockfile in the same pull request.
- Which Laravel and PHP versions does laravel-presenter support?
- Version 2.2.0 declares support for Laravel 10, 11, 12 and 13 on PHP 8.1 through 8.4, and the CI matrix actually exercises those combinations. Confirm that your exact Laravel and PHP pairing is a tested cell rather than the edge of a permissive constraint range. Treat the Laravel 13 support as tested against a pre-release and re-verify once 13.0 is generally available. PHP 8.1 is still supported even though that branch is end of life.
- How do I generate a presenter with the make:presenter command?
- Run php artisan make:presenter YourPresenterName to scaffold a presenter class in your application. Version 2.2.0 fixed the PresenterMakeCommand configure() return type, which resolves a Symfony Console signature break surfaced by Laravel 13. That fix only affects the generator command, not the runtime path that decorates models. If you have subclassed or overridden the command, re-check your signature after upgrading.
- Is laravel-presenter a replacement for Laravel API Resources?
- No, it overlaps with Laravel API Resources rather than replacing them. Presenters are typically used for view-layer formatting on models and DTOs, while API Resources are the idiomatic choice for JSON serialization in Laravel. Running both ad hoc tends to produce two competing formatting idioms in one codebase, so decide which layer owns serialization before adopting presenters. A deliberate split, presenters for Blade output and API Resources for API responses, works well for many teams.
- How do I upgrade laravel-presenter from 2.1.x to 2.2.0?
- From 2.1.x, 2.2.0 is a minor compatibility-and-hygiene release with no documented breaking changes to the public API. In practice the migration is composer update coderflexx/laravel-presenter followed by a run of your test suite. The release also drops pestphp/pest-plugin-laravel from dev dependencies, so confirm it was only ever in require-dev before assuming nothing changed in your dependency graph. Check your lockfile if any consumer tooling depended on that plugin being present transitively.
- Do I need to register the service provider or publish a config file?
- No manual registration is needed because the package service provider is auto-discovered by Laravel. In most applications the only optional step is publishing the package config if you want to customize defaults. There are no migrations, no schema changes, and no queue or cache configuration to review. The practical footprint is a new namespace for your presenter classes.
- Is laravel-presenter safe to use in production given it is a single-maintainer package?
- The blast radius is small: a handful of classes, no persistence layer, no migrations, and no container or routing replacement, so the risk of destabilizing an application is low. The main caveats are that it is a single-maintainer community package with no stated LTS or support SLA, and it does not replace your own test coverage. Because the surface area is small, vendoring or forking the package is a credible escape hatch if maintenance stalls.
- How do I test presenter classes in Laravel?
- Presenters are plain classes that wrap a model or DTO, so they are straightforward to unit test without touching the database. Instantiate the presenter with a model instance or a stub and assert on the formatted output for each attribute. Keep query logic out of the presenter so tests stay fast and side-effect free. If a presenter needs relationships, eager load them in the calling code rather than inside the presenter.
- What are the alternatives to using presenters in Laravel?
- Alternatives include Eloquent accessors and mutators, Blade components, view composers, and Laravel API Resources for JSON output. The package value is keeping formatting logic in a dedicated, reusable class rather than scattering it across models and templates. Weigh it against whatever your team already standardizes on, because adopting presenters alongside a different formatting idiom adds architectural overhead even though the package itself is technically light.