augstudios / alerts
Package for sending alerts with Laravel 5.
Requires
- php: >=5.4.0
- illuminate/session: ~5.0
- illuminate/support: ~5.0
- myclabs/php-enum: ~1.3
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.5
This package is not auto-updated.
Last update: 2020-08-21 19:01:50 UTC
README
About
This package is in very early initial development, things are very likely going change before a stable release is tagged.
Alerts is a Laravel 5 package that allows you to easily flash alerts to the Session
to be consumed on the next request.
Installation
First, install the package and it's dependencies with composer by running within your application's root folder:
composer require augstudios/alerts
Then, you will need to add the the Alerts
service provider and facade to your application's configuration in /app/config/app.php
.
'providers' => [
...
'Augstudios\Alerts\AlertsServiceProvider'
];
...
'aliases' => [
...
'Alerts' => 'Augstudios\Alerts\AlertsFacade'
];
Usage
To flash messages, to be displayed on the next request, you can use the Alerts::flash(message, type)
method:
public function save()
{
Alerts::flash('Welcome Aboard!', 'info');
return Redirect::home();
}
There also exists some shortcut methods for each alert type:
Alerts::flashInfo('Info message');
Alerts::flashWarning('Warning message');
Alerts::flashDanger('Danger message');
Alerts::flashSuccess('Success message');
To get the previously flashed alerts, use the Alerts::all()
method:
foreach(Alerts::all() as $alert){
// this is likely to change so Alert is an object
// $alert['message'] has message
// $alert['type'] has type
// $alert['dismissiable']
}
If you only want one type of alert, you can use the Alerts::ofType(type)
method:
Alerts::ofType('info');
Alerts::ofType('warning');
Alerts::ofType('danger');
Alerts::ofType('success');