Simplified Flash Messaging Alert

Jackson Chegenye (jchegenye)
1 min readAug 1, 2019

Simplified Flash Messaging Alert

A simplified flash messaging for your Laravel application using Twitter Bootstrap 4 Alerts.

Installation (Composer)

composer require jchegenye/myflashalert

Usage

Make sure you add Bootstrap to your project, you can choose to either use BootstrapCDN provided for free (see below) or download the source files here or write your own CSS based on these classes.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

Inside your controllers, you can use any of the HTTP Redirects as mentioned here except Redirecting With Flashed Session Data. Instead replace ->with() method with any of methods i.e ->success() provided by this package, see below.

Examples

//Redirecting to a named routes
public function store(){
return redirect()->route('user')->success('Successfully added!');
}
//Other redirects you can use ...

return redirect('user/edit')->success('Successfully edited!');
return redirect('user/delete')->warning('Delete?, continue...');
return redirect()->back()->error('Something went wrong!');

To display flash message in a session, add below inside your view file(s).

@include('myflashalert::message')

Methods available

->success()Flash a success message

->error()Flash error message

->warning()Flash a warning message

->info()Flash info message

That's it…

--

--