howlowck / one-message by howlowck

Laravel Package for managing messages
27
1
2
Package Data
Maintainer Username: howlowck
Maintainer Contact: howlowck@gmail.com (Hao Luo)
Package Create Date: 2014-01-21
Package Last Update: 2014-03-16
Language: PHP
License: Unknown
Last Refreshed: 2024-12-24 03:00:14
Package Statistics
Total Downloads: 27
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 2
Total Forks: 2
Total Open Issues: 3

OneMessage Build Status

For Easy Management of Messages in One singleton. Anywhere in the process you want to add a message just add it in the singleton and in the view just use it to display your messages.

Feature:

  1. Handles Flash or Same-Request Messages
  2. Handles Validation Messages
  3. Easy API

Setup:

in app/config/app.php

  • Add Service provider add 'Howlowck\OneMessage\OneMessageServiceProvider' in providers array

  • Add Facade add 'OneMessage' => 'Howlowck\OneMessage\Facades\OneMessage' in aliases array

Usage:

There are three type of messages: Error, Success, and Info.

Add Message

OneMessage::addError(['authorization' => 'You are unauthorized!!!']);

or you can throw a MessageBag in there

$v = Validator::make($data, $rules);
if ($v->fails()) {
	OneMessage::addError($v->errors());
}

Add Message for Flash
When adding to the flash data, it will not be available in the current request.

OneMessage::addError(['authorization' => 'You are unauthorized!!!'], true);

get Message

OneMessage::getError();

or get a specific message with key

OneMessage::getError('authorization');