2017 © Pedro Peláez
 

library laravel-notifications

Convenient flash notifications

image

garf/laravel-notifications

Convenient flash notifications

  • Thursday, January 26, 2017
  • by garf
  • Repository
  • 3 Watchers
  • 24 Stars
  • 373 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 14 Versions
  • 1 % Grown

The README.md

Laravel Convenient System Notifications

Laravel Version Packagist Licence Build Status, (*1)

Laravel Notifications, (*2)

Russian Documentation / Русская документация, (*3)

Notification system for Laravel 5., (*4)

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., (*5)

Now you can do this more convenient and easy way., (*6)

Install

To install, execute the following command in the console:, (*7)

``` BASH $ composer require "garf/laravel-notifications:2.*", (*8)


When completed, add to your `config/app.php` file in the `providers` section ``` PHP 'providers' => [ // ... Garf\LaravelNotifications\LaravelNotificationsServiceProvider::class, ]

If you want to use Notifications facade, add to same file at the aliases section, (*9)

``` PHP 'aliases' => [ // ... 'Notifications' => Garf\LaravelNotifications\NotificationsFacade::class, ], (*10)


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. ## Usage ### Save messages for the next request ``` php Notifications::add('Your message text', 'type', 'group');

$type param used especially for Twitter Bootstrap render. It displays alerts with respective class., (*11)

i.e. If you set type to danger, alert with class 'alert alert-danger' will be generated on toBootstrap() format method., (*12)

$group param groups messages to groups. :) On the next Request you can retrieve them by group., (*13)

Also more convenient aliases can be used:, (*14)

``` php 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');, (*15)



### Retrieving messages #### All messages ``` PHP Notifications::all()->get();

Messages by group

``` PHP Notifications::byGroup('my-group')->get();, (*16)


#### Messages by type ``` PHP Notifications::byType('warning')->get();

Format messages

You also can format messages, (*17)

JSON

You can retrieve and format all messages as JSON, (*18)

``` PHP Notifications::all()->toJson();, (*19)


Or can filter them by group or type ``` PHP Notifications::byType('success')->toJson(); Notifications::byGroup('login')->toJson();

Render with blade view files

You can also render your notifications with custom view files, (*20)

``` PHP {{ Notifications::all() }}, (*21)


And you can filter them by group or type as well: ``` PHP {{ Notifications::byType('info') }} {{ Notifications::byGroup('registration') }}

by default method uses Twitter Bootstrap alerts format., (*22)

Twitter Bootstrap can be required., (*23)

Other

Count Messages

``` PHP Notifications::all()->count();, (*24)


#### Check if messages exist ``` PHP Notifications::all()->has();

Get First Message

``` PHP Notifications::all()->first();, (*25)


#### Form Request usage If you want to display errors via Laravel Form Request, you have to override method `formatErrors()` in your Form Request Class. ``` PHP 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:, (*26)

use Illuminate\Contracts\Validation\Validator;, (*27)

Contributions

Contributions are highly appreciated., (*28)

Send your pull requests to master branch., (*29)

License

The MIT License (MIT). Please see License File for more information., (*30)

The Versions

26/01 2017

dev-master

9999999-dev

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel alert notifications

26/01 2017

2.1.1

2.1.1.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel alert notifications

29/08 2016

v2.1.0

2.1.0.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel alert notifications

17/07 2016

v2.0.0

2.0.0.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel alert notifications

14/06 2016

v1.2.5

1.2.5.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel notifications

09/06 2016

v1.2.4

1.2.4.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel notifications

08/06 2016

v1.2.3

1.2.3.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel notifications

08/06 2016

v1.2.2

1.2.2.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel notifications

08/06 2016

v1.2.1

1.2.1.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel notifications

26/12 2015

v1.2.0

1.2.0.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel notifications

25/12 2015

1.1.0

1.1.0.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dinar Garipov

laravel notifications

12/09 2015

v1.0.2

1.0.2.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

by Dinar Garipov

laravel notifications

27/08 2015

v1.0.1

1.0.1.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

by Dinar Garipov

laravel notifications

27/08 2015

v1.0.0

1.0.0.0

Convenient flash notifications

  Sources   Download

MIT

The Requires

 

by Dinar Garipov

laravel notifications