Flash Notification

Messages Component

Messages Component bring a unified notification support for Orchestra Platform.

Adding Messages

Adding a message is as easy as following:

<?php use Orchestra\Support\Facades\Messages; Messages::add('success', 'A successful message'); # You can also chain multiple messages. Messages::add('success', 'A successful message') ->add('error', 'Some error');

Appending Messages 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:

<?php use Orchestra\Messages\MessageBag; use Orchestra\Support\Facades\Messages; Messages::extend(function (MessageBag $message) { $message->add('info', 'Read-only mode'); });

Displaying Messages

By default Orchestra Platform includes orchestra/foundation::components.messages view to render the generated flash messages. However you can create your own solution such as:

<?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)); } } }

Did this page help you?