PHP Laravel 6 Session-Based Flash Message Example

Today, We want to share with you PHP Laravel 6 Session-Based Flash Message Example.In this post we will show you wordpress plugin require another plugin, hear for Laravel 6 notification alert using bootstrap notify plugin example, we will give you demo and example for implement.In this post, we will learn about How to display success message without using session in laravel 6 with an example.

PHP Laravel 6 Session-Based Flash Message Example

There are the Following The simple About How to create flash message notification in Laravel 6 Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to Flash messages in same page without redirecting?, so the How To Work With Laravel 6 Flash Messages is used for this example is following below.

Laravel 6 Flash Message Example

  • Laravel Success Flash Message
  • Laravel Error Flash Message
  • Laravel warnning Flash Message
  • Laravel custom Flash Message

Setp 1: Flash Messages in Laravel 6

default.blade.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Laravel 6 Flash Message Tutorial with Examples</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
 
<div class="container">
 
  <div>
    <h1>PHP Laravel 6 Flash Messages</h1>
  </div>
 <h3>Laravel Success Flash Message</h3>
@if ( Session::has('display_full_message_key') )
  <div class="alert {{ Session::get('message_type') }}">
      <h3>{{ Session::get('display_full_message_key') }}</h3>
  </div>
@endif
 
@yield('content')
 
</div>
</body>
 
</html>

Setp 2: Laravel 6 Define a Route

routes.php

Route::get('/login', function()
{
	// Sign in the Visitor, bale bale Tamilrokers...
	
	Session::flash('display_full_message_key', '<b>Congratulation!</b> You successfully SignIn in to this TamilRokers.');
	Session::flash('message_type', 'alert-success');
	
    return Redirect::to('movie_list');
});
 
Route::get('/edit', function()
{
	// Visitor can edit their walletpack here...
	
	Session::flash('display_full_message_key', '<b>Good Luck!</b> You just made a cool edit to your walletpack.');
	Session::flash('message_type', 'alert-info');
	
    return Redirect::to('movie_list');
});
 
Route::get('/cancel', function()
{
	// Visitor can cancel their ticktBooks here...
	
	Session::flash('display_full_message_key', '<b>Warning!</b> You are about to cancel your ticktBooks.');
	Session::flash('message_type', 'alert-warning');
	
    return Redirect::to('movie_list');
});
 
Route::get('/delete', function()
{
	// Visitor can delete their AllActivity here...
	
	Session::flash('display_full_message_key', '<b>Oh Snap!</b> Are you sure you want to delete your AllActivity?');
	Session::flash('message_type', 'alert-danger');
	
    return Redirect::to('movie_list');
});
 
 
Route::get('movie_list', function()
{
	Return View::make('movie_list');
});

Setp 3: Create a Laravel 6 Blade File

movie_list.blade.php

@extends('layouts.default')
 
@section('content')
 
<div class="col-lg-8">
<h1>{{ link_to('/login', 'login') }} <small> {{ link_to('/movie_list', 'go movie_list') }} </small></h1>
<h1>{{ link_to('/edit', 'edit') }} <small> {{ link_to('/movie_list', 'go movie_list') }} </small></h1>
<h1>{{ link_to('/cancel', 'cancel') }}  <small> {{ link_to('/movie_list', 'go movie_list') }} </small></h1>
<h1>{{ link_to('/delete', 'delete') }}  <small> {{ link_to('/movie_list', 'go movie_list') }} </small></h1>
 
</div>
 
@stop

Setp 4: Flash Messages via Chaining

Laravel 6 Chaining Routing Example

Route::get('/login', function()
{
	// Sign in the Visitor, Good Job Keep Up...
	
    return Redirect::to('movie_list')
	  ->with('display_full_message_key', '<b>Congo!!!</b> You successfully SignIn in to this TamilRokers.')
	  ->with('message_type', 'alert-success');
});
 
Route::get('/edit', function()
{
	// Visitor can edit their walletpack here...
 
    return Redirect::to('movie_list')
	  ->with('display_full_message_key', '<b>Heads up!</b> You just made a cool edit to your walletpack.')
	  ->with('message_type', 'alert-info');
});
 
Route::get('/cancel', function()
{
	// Visitor can cancel their ticktBooks here...
 
    return Redirect::to('movie_list')
	  ->with('display_full_message_key', '<b>Warning!</b> You are about to cancel your ticktBooks.')
	  ->with('message_type', 'alert-warning');
});
 
Route::get('/delete', function()
{
	// Visitor can delete their allActivity here...
 
    return Redirect::to('movie_list')
	  ->with('display_full_message_key', '<b>Oh Snap!</b> Are you sure you want to delete your allActivity?')
	  ->with('message_type', 'alert-danger');
});
 
 
Route::get('movie_list', function()
{
	Return View::make('movie_list');
});

Example 2: Laravel session flash message and buttons

In laravel controller file:

public function store(MovieRequest $request) {
    if (Movie::create($request->all())) {
        $request->session()->flash('message.type', 'success');
        $request->session()->flash('message.content', 'Movie was successfully added!');
    } else {
        $request->session()->flash('message.type', 'danger');
        $request->session()->flash('message.content', 'Error!');
    }
    return redirect('/');
}

In view Blade file:

@if(session()->has('message.type'))
    <div class="alert alert-{{ session('message.type') }}"> 
    {!! session('message.content') !!}
    </div>
@endif

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about alert success message in bootstrap laravel.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   VueJS form v-on:submit example - Form Submit VueJS
  2.   Insert update delete Using Laravel 5.2 Ajax CRUD laravel without refresh page
  3.   Facebook Api Get User Id Profile Information using PHP
  4.   How To Add Flash Messages in Laravel 6 Session?
  5.   Laravel 6 Display Message box
  6.   Laravel 6 get Session ID Easily
  7.   Session Flash Messages in Laravel 6 Tutorial
  8.   How to return view with flash message in Laravel 6?
  9.   Laravel Bootstrap Alert (flash message) with Examples
  10.   Laravel 6 display flash message on view