2.2 documentation

Messages Component bring a unified notification support for Laravel 4 and Orchestra Platform 2.

Table of Content

Version Compatibility

Laravel Messages
4.2.x 2.2.x

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require": {
        "orchestra/messages": "2.2.*"
    }
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplify by using the following command:

composer require "orchestra/messages=2.2.*"

Configuration

Add Orchestra\Messages\MessagesServiceProvider service provider in app/config/app.php.

'providers' => array(

    // ...

    'Orchestra\Messages\MessagesServiceProvider',
),

Aliases

You might want to add Orchestra\Messages\Facade to class aliases in app/config/app.php:

'aliases' => array(

    // ...

    'Orchestra\Messages' => 'Orchestra\Messages\Facade',
),

Usage

Adding a Message

Adding a message is as easy as following:

Orchestra\Messages::add('success', 'A successful message');

You can also chain messages:

Orchestra\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:

Orchestra\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 = Orchestra\Messages::retrieve();

if ($message instanceof Orchestra\Messages\MessageBag) {
    foreach (['error', 'info', 'success'] as $key) {
        if ($message->has($key)) {
            $message->setFormat(
                '<div class="alert alert-'.$key.'">:message</div>'
            );
            echo implode('', $message->get($key));
        }
    }
}