diegoalvarezb / laravel-front-messages by diegoalvarezb

Management of flash messages and custom messages in the same way.
10
0
2
Package Data
Maintainer Username: diegoalvarezb
Package Create Date: 2017-08-30
Package Last Update: 2017-09-03
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-03-27 03:07:27
Package Statistics
Total Downloads: 10
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

laravel-front-messages

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