diegoalvarezb/laravel-front-messages

Management of flash messages and custom messages in the same way.

v1.0.1 2017-08-31 16:06 UTC

This package is auto-updated.

Last update: 2024-12-06 05:20:33 UTC


README

This tool handle front messages in Laravel.

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.

So using this package you could manage messages regardless of whether you are rendering a view or redirecting to another route.

Requirements

  • PHP >= 5.6
  • Laravel >= 5.0

Installation and configuration

Package installation with composer:

composer require diegoalvarezb/laravel-front-messages

And add the service provider in your config/app.php file:

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:

$this->addHtmlMessage($type, $message);

You can add as many messages as you like in every moment.

Customize messages view

You have to execute this command:

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:

@include('vendor.front-messages.messages')

Examples

There are four types of messages:

  • danger
  • info
  • success
  • warning
$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