orchestra / messages
Messages Component for Laravel and Orchestra Platform
Fund package maintenance!
Liberapay
paypal.me/crynobone
Installs: 90 349
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- orchestra/contracts: ^6.0
- orchestra/support: ^6.0
Requires (Dev)
- orchestra/testbench: ^6.17
This package is auto-updated.
Last update: 2024-11-18 02:44:09 UTC
README
Messages Component bring a unified notification support for Laravel and Orchestra Platform.
Version Compatibility
Installation
To install through composer, run the following command from terminal:
composer require "orchestra/messages"
Configuration
Add Orchestra\Messages\MessagesServiceProvider
service provider in config/app.php
.
'providers' => [ // ... Orchestra\Messages\MessagesServiceProvider::class, ],
Aliases
You might want to add Orchestra\messages\Facades\Messages
to class aliases in config/app.php
:
'aliases' => [ // ... 'Messages' => Orchestra\Support\Facades\Messages::class, ],
Usage
Adding a Message
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');
Extending a Message to Current Request
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'); });
Displaying the Message in a View
Here's an example how you can display the message:
<?php $message = Messages::copy(); 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)); } } }