Package Data | |
---|---|
Maintainer Username: | garf |
Maintainer Contact: | garipov.dinar@gmail.com (Dinar Garipov) |
Package Create Date: | 2015-07-23 |
Package Last Update: | 2017-01-26 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-22 03:16:12 |
Package Statistics | |
---|---|
Total Downloads: | 2,976 |
Monthly Downloads: | 66 |
Daily Downloads: | 0 |
Total Stars: | 21 |
Total Watchers: | 5 |
Total Forks: | 6 |
Total Open Issues: | 0 |
Russian Documentation / Русская документация
Notification system for Laravel 5.
Often after saving some data from user you have to redirect to proper page and notificate user that everything done successfully or some errors appeared.
Now you can do this more convenient and easy way.
To install, execute the following command in the console:
$ composer require "garf/laravel-notifications:2.*"
When completed, add to your config/app.php
file in the providers
section
'providers' => [
// ...
Garf\LaravelNotifications\LaravelNotificationsServiceProvider::class,
]
If you want to use Notifications
facade, add to same file at the aliases
section
'aliases' => [
// ...
'Notifications' => Garf\LaravelNotifications\NotificationsFacade::class,
]
To change the templates, please execute the following command in the console:
php artisan vendor:publish --provider="Garf\LaravelNotifications\LaravelNotificationsServiceProvider" --tag="config"
Now you will be able to set any view file for notifications render in config/laravel-notifications.php
.
Optionally you can execute the following command in the console to edit the default template, instead of using your own:
php artisan vendor:publish --provider="Garf\LaravelNotifications\LaravelNotificationsServiceProvider" --tag="views"
Note: If you publish the view and edit it, do not change the name of the view in the config file.
Notifications::add('Your message text', 'type', 'group');
$type
param used especially for Twitter Bootstrap render. It displays alerts with respective class.
i.e. If you set type
to danger
, alert with class 'alert alert-danger' will be generated on toBootstrap()
format method.
$group
param groups messages to groups. :) On the next Request you can retrieve them by group.
Also more convenient aliases can be used:
Notifications::info('Your message text', 'group');
Notifications::success('Your message text', 'group');
Notifications::warning('Your message text', 'group');
Notifications::danger('Your message text', 'group');
Notifications::error('Your message text', 'group');
Notifications::all()->get();
Notifications::byGroup('my-group')->get();
Notifications::byType('warning')->get();
You also can format messages
You can retrieve and format all messages as JSON
Notifications::all()->toJson();
Or can filter them by group or type
Notifications::byType('success')->toJson();
Notifications::byGroup('login')->toJson();
You can also render your notifications with custom view files
{{ Notifications::all() }}
And you can filter them by group or type as well:
{{ Notifications::byType('info') }}
{{ Notifications::byGroup('registration') }}
by default method uses Twitter Bootstrap alerts format.
Twitter Bootstrap can be required.
Notifications::all()->count();
Notifications::all()->has();
Notifications::all()->first();
If you want to display errors via Laravel Form Request, you have to override method formatErrors()
in your Form Request Class.
public function formatErrors(Validator $validator){
foreach ($validator->errors()->all() as $error) {
Notifications::add($error, 'danger');
}
return $validator->errors()->getMessages();
}
Don't forget to import Validator
class in head of the file:
use Illuminate\Contracts\Validation\Validator;
Contributions are highly appreciated.
Send your pull requests to master
branch.
The MIT License (MIT). Please see License File for more information.