Download the PHP package coderflexx/laravel-presenter without Composer
On this page you can find all versions of the php package coderflexx/laravel-presenter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coderflexx/laravel-presenter
More information about coderflexx/laravel-presenter
Files in coderflexx/laravel-presenter
Package laravel-presenter
Short Description Write Clean/Reusable Code with Presenters.
License MIT
Homepage https://github.com/coderflexx/laravel-presenter
Informations about the package laravel-presenter
Laravel Presenter
A clean way to present your model attributes without putting them in the wrong file.
- Laravel Presenter
- Installation
- Usage
- Model Implementation
- Create New Model Presenter class
- Using the
Presenter
Generated Class - Example
- Adding Another Presenter Type
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
The implementation of this package is so simple, all what you need to do is the following:
Model Implementation
- Implement
CanPresent
Interface - Use
UsesPresenters
Trait
Create New Model Presenter class
This package gives you an easy way to generate new Presenter
class, all you need to do is to use presenter:make
command.
UserPresenter
in our case, leaves by default in App\Presenters
.
This is the contents of the UserPresenter
file:
If you want to change the directory, you have two options.
First options is to set the full namespace while you're creating the presenter class
Or change presenter_namespace
from config/laravel-presenter
file.
Using the Presenter
Generated Class
After you create the presenter class, you need to register it on the Model
by adding the $presenters
protected property:
By default, the type of your presenter class is default
, but you can use as many of presenters you want, just by identifying the type in $presenters
property.
Example
Now, after we generated the presenter
class, and we implemented it successfully in our model, we can use it like so:
In your UserPresenter
class or any presenter class you generated.
We add a new method to present the fullName
.
In your blade or any place you want, you can do:
Your application will show the full name from the method you added.
Adding Another Presenter Type
Like I said above, by default the type will be default
but, you can add more types as you need.
Here is an example:
Generate new UserSettingPresenter
Add anything to UserSettingPresenter
method
Finally, set setting
as a type:
By that, you can split your logic and make your code base even cleaner.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Oussama Sid
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-presenter with dependencies
spatie/laravel-package-tools Version ^1.9.2
illuminate/console Version ^8.75|^9.0|^10.0|^11.0
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0