Package Data | |
---|---|
Maintainer Username: | AndreasHeiberg |
Maintainer Contact: | heibergandreas@gmail.com (Andreas Peter Heiberg) |
Package Create Date: | 2014-03-23 |
Package Last Update: | 2016-06-28 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-09 15:01:35 |
Package Statistics | |
---|---|
Total Downloads: | 8,968 |
Monthly Downloads: | 4 |
Daily Downloads: | 0 |
Total Stars: | 12 |
Total Watchers: | 3 |
Total Forks: | 5 |
Total Open Issues: | 1 |
A site notification package for laravel.
Currently let's you easily flash notifications to the session. It also supports laravels translation package out of the box.
You can install the package for your Laravel project through Composer.
# Laravel 4x
composer require andheiberg/notify:1.*
# Laravel 5x
composer require andheiberg/notify:2.*
Register the service provider in app/config/app.php
.
Andheiberg\Notify\NotifyServiceProvider::class,
Add the alias to the list of aliases in app/config/app.php
.
'Notify' => Andheiberg\Notify\Facades\Notify::class,
The packages provides you with some configuration options.
To create the configuration file run this command in your command line app:
# Laravel 4x
php artisan config:publish andheiberg/notify
# Laravel 5x
php artisan vendor:publish --provider="Andheiberg\Notify\NotifyServiceProvider"
The configuration file will be published here: app/config/packages/andheiberg/notify/config.php
.
By default, the package has some notification types defined in its configuration file. The default types are success
, error
, warning
and info
.
Every type can be called as a function.
Notify::info('This is an info message.');
Notify::error('Whoops, something has gone wrong.');
You can of course add your own types by adding them to your own config file. See above on how to publish the config file.
You can also pass a language tag for easy localization.
Notify::success('auth.login-successful'); // Calls Lang::get('auth.login-successful') behind the scene
Notify::warning('auth.verification-email-sent', ['email' => 'test@gmail.com']) // You can also pass replacements
Notify
class is just an extension of Illuminate's MessageBag
class, which means we can use all of its functionality to display messages.
@foreach (Notify::all() as $notification)
{{ $notification }}
@endforeach
Or if you'd like to display a single notification for a certain level.
@if (Notify::has('success'))
{{ Notify::first('success') }}
@endif
If you'd like to learn more ways on how you can display messages, please take a closer look to Illuminate's MessageBag
class.
@if (Notify::all())
<div class="container">
@foreach (Notify::get('success') as $alert)
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ $alert }}
</div>
@endforeach
@foreach (Notify::get('error') as $alert)
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ $alert }}
</div>
@endforeach
@foreach (Notify::get('info') as $alert)
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ $alert }}
</div>
@endforeach
@foreach (Notify::get('warning') as $alert)
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ $alert }}
</div>
@endforeach
</div>
@endif