laravel flash message Notification in Blade template

Today, We want to share with you laravel flash message.In this post we will show you Laravel – Implement Flash Messages with example, hear for how to show error message in laravel blade we will give you demo and example for implement.In this post, we will learn about Laravel session flash message include html tag link href blade view with an example.

laravel flash message

There are the Following The simple About laravel ajax redirect with message Full Information With Example and source code.

As I will cover this Post with live Working example to develop Use Flash Message in Blade template, so the How to create flash message notification in Laravel is used for this example is following below.

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 laravel 6 redirect with message session.
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.

Step 1: flash-notification blade file

resources/views/flash-notification.blade.php

@if ($notification = Session::get('success'))
<div class="alert alert-success alert-block">
	<button type="button" class="close" data-dismiss="alert">×</button>	
        <strong>{{ $notification }}</strong>
</div>
@endif


@if ($notification = Session::get('error'))
<div class="alert alert-danger alert-block">
	<button type="button" class="close" data-dismiss="alert">×</button>	
        <strong>{{ $notification }}</strong>
</div>
@endif


@if ($notification = Session::get('warning'))
<div class="alert alert-warning alert-block">
	<button type="button" class="close" data-dismiss="alert">×</button>	
	<strong>{{ $notification }}</strong>
</div>
@endif


@if ($notification = Session::get('info'))
<div class="alert alert-info alert-block">
	<button type="button" class="close" data-dismiss="alert">×</button>	
	<strong>{{ $notification }}</strong>
</div>
@endif


@if ($errors->any())
<div class="alert alert-danger">
	<button type="button" class="close" data-dismiss="alert">×</button>	
	Please check the form below for errors
</div>
@endif

Step 2: use flash-notification file in theme

resources/views/layouts/app.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Styles -->
    <link href="/css/app.css" rel="stylesheet">
</head>
<body>


    <div id="app">
        @include('flash-notification')


        @yield('content')
    </div>


    <!-- Scripts -->
    <script src="/js/app.js"></script>
</body>
</html>

Step 3: use flash messages with redirect

1. Redirect with success notification

public function storeProduct(Request $request)
{
	$this->validate($request,[
        'title' => 'required',
        'details' => 'required'
        ]);


	$products = Product::create($request->all());


	return back()->with('success','Product created successfully!');
}

2. Redirect with error notification

public function storeProduct(Request $request)
{
    return redirect()->route('products')
        ->with('error','You have no permission for this page!');
}

3. Redirect with warning notification

public function storeProduct(Request $request)
{
    return redirect()->route('products')
            ->with('warning','Don't Open this link);
}

4. Redirect with info notification

public function storeProduct(Request $request)
{
    $this->validate($request,[
        'title' => 'required',
        'details' => 'required'
        ]);


    $products = Product::create($request->all());


    return back()->with('info','You added new products, follow next step!');
}

5. Validation Error

public function storeProduct(Request $request)
{
    $this->validate($request,[
        'title' => 'required',
        'details' => 'required'
        ]);


    .....
}


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel 7 Implement Flash Messages with example
  2.   How To Add Flash Messages in Laravel 6 Session?
  3.   PHP Laravel 6 Session-Based Flash Message Example
  4.   How to return view with flash message in Laravel 6?
  5.   Simple JQuery Ajax Request Example with Laravel 6
  6.   Laravel 7 jQuery Ajax Request Tutorial
  7.   Laravel 6 get Session ID Easily
  8.   PHP Laravel 6 Flash Message Notification
  9.   Laravel 7 Generate/Create PDF File Tutorial From Scratch
  10.   jQuery Ajax GET & POST REQUEST Methods PHP MySQLi