Hi, Guys
In this tutorial i will let you know how to implement flash message in laravel 5.5 application. We can simply add info, success, error, warning and primary type of flash messages. Here in this tutorial i will use "mercuryseries/flashy" composer package, help of this package i will make simple example.
As we know well, flash message is very important to notify when record is created new, edited or deleted. So when you remove new record from list then flash message should appear "Item Deleted Successfully". I would be good to display this way message. So in this example you can see how i implemented flash message in laravel 5.5 from scratch.
You can see bellow screen shot flash message layout in corner green notification.
Step 1: Install mercuryseries/flashy Package
First of the thing is we have to install mercuryseries/flashy composer package for flash message. So simply run bellow composer command for install package.
composer require mercuryseries/flashy
After install successfully above mercuryseries/flashy package we need to add into providers and aliases array of configuration file. So let's add following way:
config/app.php
<?php
return [
....
'providers' => [
....
MercurySeries\Flashy\FlashyServiceProvider::class
],
'aliases' => [
....
'Flashy' => MercurySeries\Flashy\Flashy::class,
]
Step 2: Add Route For Example
Now, in this step we will create new route for flash message and we will write code for generate flash message. So let's add following route:
routes/web.php
Route::get("flash","HomeController@flash");
Step 3: Add Method in HomeController
Here, we have to add flash() on HomeController file. So there we will write code for flash message, so add bellow method on HomeController:
app/Http/Controllers/HomeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PDF;
class HomeController extends Controller
{
public function flash()
{
flashy()->success('You get success notification.', 'hdtuto.com');
return view('flash');
}
}
Step 4: create flash.blade.php file
In last step, we have to add flash.blade.php view blade file. In this file we have to just write some html table code. So let's create blade file and put bellow code:
resources/views/flash.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="container">
<p>Welcome to my website...</p>
</div>
<script src="//code.jquery.com/jquery.js"></script>
@include('flashy::message')
</body>
</html>
Now you are ready to run full example.
You can also set following flash message by this way:
Flashy::info('Message', 'http://your-awesome-link.com')
Flashy::success('Message', 'http://your-awesome-link.com')
Flashy::error('Message', 'http://your-awesome-link.com')
Flashy::warning('Message', 'http://your-awesome-link.com')
Flashy::primary('Message', 'http://your-awesome-link.com')
Flashy::primaryDark('Message', 'http://your-awesome-link.com')
Flashy::muted('Message', 'http://your-awesome-link.com')
Flashy::mutedDark('Message', 'http://your-awesome-link.com')
you can get more information about "mercuryseries/flashy" from here : mercuryseries/flashy.
I hope you found your best solution...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example