orchestra/messages

Messages Component for Laravel and Orchestra Platform
91,707 3
Install
composer require orchestra/messages
Latest Version:v6.1.0
PHP:^7.3 || ^8.0
License:MIT
Last Updated:Apr 17, 2021
Links: GitHub  ·  Packagist
Maintainer: crynobone

Messages Component for Laravel and Orchestra Platform

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

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status

Version Compatibility

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
6.x 4.x
7.x 5.x
8.x 6.x

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

Related Packages

orchestra/support-providers

Support (Providers) Component for Laravel and Orchestra Platform

179,172 3
orchestra/support

Support Component for Orchestra Platform

503,076 16
orchestra/parser

XML Document Parser for Laravel and PHP

1,788,872 458
orchestra/imagine

Imagine (Wrapper) Component for Laravel 5

227,193 66
orchestra/support-core

Support (Core) Component for Orchestra Platform

178,771 2