Package Data | |
---|---|
Maintainer Username: | letrunghieu |
Maintainer Contact: | letrunghieu.cse09@gmail.com (Hieu Le) |
Package Create Date: | 2015-04-08 |
Package Last Update: | 2018-04-24 |
Home Page: | https://www.hieule.info/products/laravel-v4-v5-global-site-message-system/ |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-10 15:04:06 |
Package Statistics | |
---|---|
Total Downloads: | 5,612 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 6 |
Total Watchers: | 1 |
Total Forks: | 4 |
Total Open Issues: | 2 |
Global site message system for Laravel 4 (for Laravel 5, see laravel-5 branch)
You will need Composer to use this package. There is a nice tutorial of using Composer for those who are not familiar with this awesome tool.
Add this to your composer.json
file.
"hieu-le/laravel-alert": "~1.0"
Run composer update
to update all dependencies. After that, register the service provider for Laravel by adding this line to the providers
array in app/config/app.php
'HieuLe\Alert\AlertServiceProvider',
And add this alias to the aliases
array in app/config/app.php
'Alert' => 'HieuLe\Alert\Facades\Alert',
To add new message, use one of these four method. The name of each method is the type of the message you want to add.
Alert::success($message);
# or
Alert::info($message);
# or
Alert::warning($message);
# or
Alert::error($message);
To make these message available in next request, you must call Alert::flash()
at least one time.
Alert::flash()
In your view, use the method Alert::dump
to display these messages. By default, each type of message is rendered with the format of Bootstrap 3 alert. You can change they appearance by reading the configuration section below.
You can get more control over this package by modifying these configuations. First of all, publish the package config, so that you can edit the copied version:
php artisan config:publish hieu-le/laravel-alert
Open app/config/packages/hieu-le/laravel-alert/config
file and change these settings:
session_key
: the name of the session key that stored messages between requests. You normally do not want to edit its valueicon
: the icon for each type of message when rendered in the default view. You can remove the value of one key to disable the icon for that type of message.view
: the name of the view being used to render each type of message. In the view, you can use 2 variables: $icon
is the icon of this message type; $messages
: an array of messages of the current message type.To display the validation error, simply add another parameter to the Alert::dump
method. For example
// In each view, there is a special variable call $errors
// This is the validation errors that is set by calling "withError" method as
// guided at http://laravel.com/docs/4.2/validation#error-messages-and-views
echo Alert::dump($errors->all());