PHP code example of goomcoom / laravel-messages

1. Go to this page and download the library: Download goomcoom/laravel-messages library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

goomcoom / laravel-messages example snippets


// config/app.php

[
    'providers' => [
        // ...
        GoomCoom\Messages\MessagesServiceProvider::class,
    ],
    
    'aliases' => [
        // ...
        'Messages' => GoomCoom\Messages\Facades\Messages::class,
    ],
];

// config/goomcoom-laravel-messages.php

return [
    /**
     * –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     * Bags
     * –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     * These are the bags that messages can be added to.
     */

    'bags' => [
        'error',
        'info',
        'success',
        'warning',
    ],
];


    Messages::add('error', 'Cannot do that!', 'Something went wrong.');
    Messages::add('info', 'Something else happened.');

    /*
        {
            ...
            meta: {
                messages: {
                    error: [
                        'Cannot do that!',
                        'Something went wrong.'
                    ],
                    info: [
                        'Something else happened.'
                    ]
                }
            }
        }
    */

// Returns Illuminate/Support/MessageBag with "warning" messages
Messages::getBag('warning');

Messages::getAll();

/*
    [
        'error' => [ ... ],
        'info' => [ ... ],
        'success' => [ ... ],
        'warning' => [ ... ],
    ]
*/

// Returns boolean
Messages::hasAny();

// Removes all messages from the success bag.
Messages::remove('success', '*');

// Removes the "To be removed" & "Also to be removed" messages from the error bag'
Messages::remove('error', 'To be removed', 'Also to be removed');

// Removes all messages
Messages::reset();
shell script
$ php artisan vendor:publish --tag=goomcoom-laravel-messages