Package Data | |
---|---|
Maintainer Username: | crynobone |
Maintainer Contact: | crynobone@gmail.com (Mior Muhammad Zaki) |
Package Create Date: | 2014-07-21 |
Package Last Update: | 2021-04-17 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-10-30 15:19:43 |
Package Statistics | |
---|---|
Total Downloads: | 90,273 |
Monthly Downloads: | 76 |
Daily Downloads: | 6 |
Total Stars: | 3 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Messages Component bring a unified notification support for Laravel and Orchestra Platform.
Laravel | Messages :----------|:---------- 5.5.x | 3.5.x 5.6.x | 3.6.x 5.7.x | 3.7.x 5.8.x | 3.8.x
To install through composer, simply put the following in your composer.json
file:
{
"require": {
"orchestra/messages": "^3.5"
}
}
And then run composer install
from the terminal.
Above installation can also be simplify by using the following command:
composer require "orchestra/messages=^3.5"
Add Orchestra\Messages\MessagesServiceProvider
service provider in config/app.php
.
'providers' => [
// ...
Orchestra\Messages\MessagesServiceProvider::class,
],
You might want to add Orchestra\Support\Facades\Messages
to class aliases in config/app.php
:
'aliases' => [
// ...
'Messages' => Orchestra\Support\Facades\Messages::class,
],
Adding a message is as easy as following:
Messages::add('success', 'A successful message');
You can also chain messages:
Messages::add('success', 'A successful message')
->add('error', 'Some error');
There might be situation where you need to extend a message to the current response instead of the following request. You can do this with:
Messages::extend(function ($message) {
$message->add('info', 'Read-only mode');
});
Here's an example how you can display the message:
<?php
$message = Messages::retrieve();
if ($message instanceof Orchestra\Messages\MessageBag) {
$message->setFormat('<div class="alert alert-:key">:message</div>');
foreach (['error', 'info', 'success'] as $key) {
if ($message->has($key)) {
echo implode('', $message->get($key));
}
}
}