spajz / msg by spajz

Simple notification system for Laravel 4
8
0
1
Package Data
Maintainer Username: spajz
Maintainer Contact: rasplinjac@gmail.com (Spajz)
Package Create Date: 2014-03-25
Package Last Update: 2014-03-25
Language: PHP
License: MIT
Last Refreshed: 2024-11-11 15:11:49
Package Statistics
Total Downloads: 8
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Simple notification system for Laravel 4


  • Extends Laravel MessageBag class.
  • Custom template support (comes with Bootstrap3, Bootstrap2 and Foundation5 template).
  • Blade string like template.
  • Custom groups.
  • Formats and sorting for groups and messages.
  • Instant and flashable notifications...

Installation

Application specific modules in Laravel 4 can be enabled by adding the following to your "composer.json" file:

"spajz/msg": "dev-master"

Then composer update.

Add a new provider to your providers list in "app/config/app.php":

'Spajz\Msg\MsgServiceProvider',

Also add a new alias to aliases list in "app/config/app.php":

'Msg' => 'Spajz\Msg\Facades\Msg',

Configuration

If you want to edit default config file, just publish it to your app folder.

php artisan config:publish spajz/msg

Usage

Add default messages

// Default groups
Msg::success('Success message');
Msg::error('Error message');
Msg::danger('Danger message');
Msg::info('Info message');
Msg::warning('Warning message');

// Multiple messages
Msg::info(array('First message', 'Second'));

Custom groups

You can add custom groups to config, and then use them like default groups.

// Custom groups
Msg::exit('Exit message');
Msg::break('Break message');

// Custom key
Msg::custom('bar', $message, 'Bar group message format :message');
Msg::custom('foo', array($foo, $bar, 'Some text'), 'Format :message');

Show messages

// Show all messages from the previous request
Msg::show();

// Only info messages
Msg::showInfo();

// With message format
Msg::showInfo($foo, ':key message: :message!');

// Show all messages in same request
Msg::instant();

// Only info with format
Msg::showInfoInstant($foo, ':key message: :message!');

// Custom group with format
Msg::showExitInstant($bar, ':key message: :message!');

Templates

// Add default template for all groups
Msg::setTemplate('myTemplate');

// Assign template to the specific group
Msg::setTemplates('info', 'myInfoTemplate');

// Assign Laravel Blade string like template
$blade = '<div class="box-{{ $key }}">';
$blade .= '@foreach ($messages as $message)';
$blade .= '<b>{{ $message }}</b>';
$blade .= '@endforeach';
$blade .= '</div>';

Msg::setTemplates('info', $blade, true);

// Delete all templates
Msg::deleteTemplates();

// Delete specific group template
Msg::deleteTemplates('danger');

Examples

// Add and show message instantly
echo Msg::danger('Something is wrong')->showDangerInstant();

// Set group format
Msg::setGroupFormat('info', '<b>:message</b>');

// Get raw messages data
Msg::getMessages();

// Set display mode single or group
Msg::setDisplayMode('single');