laravel-front-messages
This tool handle front messages in Laravel., (*1)
As Laravel allows by default to add flash (session) messages that will be shown in the next page, this package allows to join those messages with the ones you want to add in the current view., (*2)
So using this package you could manage messages regardless of whether you are rendering a view or redirecting to another route., (*3)
Requirements
- PHP >= 5.6
- Laravel >= 5.0
Installation and configuration
Package installation with composer:, (*4)
composer require diegoalvarezb/laravel-front-messages
And add the service provider in your config/app.php
file:, (*5)
Diegoalvarezb\FrontMessages\FrontMessagesServiceProvider::class
Add message
To add a message in a controller you have to add the Diegoalvarezb\FrontMessages\FrontMessagesTrait
. With this trait you could use the addHtmlMessage
method:, (*6)
$this->addHtmlMessage($type, $message);
You can add as many messages as you like in every moment., (*7)
Customize messages view
You have to execute this command:, (*8)
php artisan vendor:publish --tag=front-messages
This command will copy the default view into the resources/views/vendor folder. After that, you could edit this file, and use it in any blade template:, (*9)
@include('vendor.front-messages.messages')
Examples
There are four types of messages:
- danger
- info
- success
- warning, (*10)
$this->addHtmlMessage('danger', 'This is an example of danger message');
$this->addHtmlMessage('info', 'This is an example of info message');
$this->addHtmlMessage('success', 'This is an example of success message');
$this->addHtmlMessage('warning', 'This is an example of warning message');
License
MIT, (*11)