Alert is designed to make flashing messages in Laravel Applications a breeze. Tested and works in Laravel 5 or less
Add alert in your composer.json file:
"require": {
"digitlimit/alert": "dev-master"
}Then run
composer updateIn Laravel 5 include Alert Service Provider within config/app.php or app/config/app.php in Laravel 4
'providers' => [
'Digitlimit\Alert\AlertServiceProvider'
];You can also include alert facade in aliases array in same file above i.e config/app.php or app/config/app.php in Laravel 4
'aliases' => [
'Alert' => 'Digitlimit\Alert\Facades\Alert'
];In your controller simply set your alert before redirection like so:
In laravel 5 controller for example:
<?php namespace App\Http\Controllers;
use \Alert; //using Alert Facades
class UserController extends Controller
{
public function postRegister(UserRegisterRequest $request)
{
Alert::form('Your account was successfully created','Congratulations')->success()->closable()->showIcon();
return redirect()->route('users.getRegister');
}
}Then in your view your can include the flash message to your view like so:
<div class"registration_form">
@include('alert::form')
<form method="POST" action="{{URL::route('users.postRegister')}}" novalidate>
<div class="form-group">
<label for="name">First Name</label>
<input type="text" id="first_name" class="form-control" name="first_name" placeholder="First Name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" class="form-control" name="email" placeholder="Email Address">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" class="form-control" name="password">
</div>
<button type="submit" class="btn btn-success">Register</button>
</form>
</div>There are basically three types of alert messages you can flash
Some where in the controller:
//This simply displays a success message
Alert::form('Your account was successfully created','Congratulations')->success();
Some where in the view:
@include('alert::form')Some where in the controller:
//This simply displays a success message
Alert::notify('Your account is going to expire today.','Info')->info();
Some where in the view layout:
@include('alert::notify')Some where in the controller:
//This simply displays a success message
Alert::modal('Thanks for joining us.','Title')->info();Some where in the view layout:
@include('alert::modal')