presenter
Easy view presenters for Laravel that keep display logic out of models and views.
Repository Health
Technical Analysis
Laracasts Presenter is a small PHP package that implements the view-presenter pattern for Laravel and Eloquent applications. When a bit of formatting logic needs to run before entity data is shown in a view, a presenter gives it a home - not hard-coded in the template, and not bloating the model.
You write a presenter class that extends the package’s base Presenter, add a trait to your model, and then call present() in your views to access formatted, display-ready attributes and methods. The result is cleaner models, tidier views, and one obvious place to change presentation logic.
What You Get
- A base
Presenterclass to extend for display formatting methods - A
PresentableTraitthat auto-instantiates and caches the presenter - A
present()accessor for reaching formatted attributes in views - Transparent access to the underlying entity’s raw attributes
- A clear, single home for presentation logic separate from models and views
Common Use Cases
- Formatting a user’s full name or display name for a view
- Rendering human-friendly dates and statuses from model data
- Keeping presentation logic out of Eloquent models
- Centralizing view formatting so it is easy to find and change
Under The Hood
Architecture - The core is a small Laracasts\Presenter\Presenter base class (src/Laracasts) that wraps an entity and exposes its attributes via magic accessors, plus a PresentableTrait that lazily instantiates and caches the configured presenter behind a present() method. Tech Stack - Plain PHP with a Composer autoloader, designed to drop into Laravel/Eloquent but with no hard framework coupling beyond the trait convention; a small PHPUnit test suite accompanies it. Code Quality - The library is intentionally tiny and single-purpose, which keeps it easy to read and audit, though the project sees infrequent maintenance given its stable, complete scope. API Design - The pattern is almost invisible: extend Presenter, add a trait, set one property, and call present(), so the learning curve is minimal and the intent reads clearly at every call site.