howlowck / one-message
Laravel Package for managing messages
Requires
- php: >=5.3.0
- illuminate/session: ~4
- illuminate/support: ~4
Requires (Dev)
- mockery/mockery: dev-master@dev
This package is not auto-updated.
Last update: 2024-11-19 02:55:00 UTC
README
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:
- Handles Flash or Same-Request Messages
- Handles Validation Messages
- Easy API
Setup:
in app/config/app.php
-
Add Service provider add
'Howlowck\OneMessage\OneMessageServiceProvider'
inproviders
array -
Add Facade add
'OneMessage' => 'Howlowck\OneMessage\Facades\OneMessage'
inaliases
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');