How To Work With Laravel 6 Flash Messages?

Today, We want to share with you How To Work With Laravel 6 Flash Messages?.In this post we will show you laravel flash message, hear for Flash Message with Laravel 6 Tutorial we will give you demo and example for implement.In this post, we will learn about laravel flash message ajax with an example.

How To Work With Laravel 6 Flash Messages?

There are the Following The simple About How To Work With Laravel 6 Flash Messages? Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 6.0 flash message, so the laravel get flash message in blade is used for this example is following below.

Creating our Laravel 6 Scaffolding

composer create-project laravel/laravel laravel-projetc-app 
cd laravel-projetc-app

create a flash message the syntax

Session::flash('message', 'It is a simple flash message containing subscriptions to the member!'); 

Displaying PHP Laravel Session Based Flash Messages in plain display HTML source code

Read Also:  How to decode JSON data with jQuery / JavaScript?

@if(Session::has('message'))
{{ Session::get('message') }}
@endif

Show the Data content of a PHP Laravel 6 flash message in your Laravel blade view file.

 @if ( Session::has('message') )
         
  M.toast({html: '{{ Session::get('message') }}'}) 
                 
@endif

Laravel Flash messages Demo

web.php

Route::get('/', function(){
return  view('welcome');
});
Route::get('/login', function()
{
	// Sign in the member and all that...
	
	Session::flash('msg_data_content', ' You successfully logged in to this Blogspot.');
	Session::flash('msg_display_type', 'alert-success');
	
    return Redirect::to('/');
});
 
Route::get('/edit', function()
{
	// Member can edit their profile here...
	
	Session::flash('msg_data_content', 'You just create a cool edit/update to simple profile.');
	Session::flash('msg_display_type', 'alert-info');
	
    return Redirect::to('/');
});
 
Route::get('/cancel', function()
{
	// Member can cancel their membership here...
	
	Session::flash('msg_data_content', 'You are about to cancel simple membership.');
	Session::flash('msg_display_type', 'alert-warning');
	
    return Redirect::to('/');
});
 
Route::get('/delete', function()
{
	// Member can delete their account here...
	
	Session::flash('msg_data_content', 'Are you sure you want to remove simple account?');
	Session::flash('msg_display_type', 'alert-danger');
	
    return Redirect::to('/');
});
 
 
// Route::get('home', function()
// {
// 	Return View::make('home');
// });

resources/views/app.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Laravel 6 otifications - www.pakainfo.com</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</head>
<body>
        {{-- <a class="btn" onclick="">Toast!</a> --}}
        <div class="container">
                <h1>Laravel Flash Messages with Materialize CSS Toasts</h1>
              </div>
             
            @if ( Session::has('msg_data_content') )
             
              <div class="alert {{ Session::get('msg_display_type') }}">
                <script> M.toast({html: '{{ Session::get('msg_data_content') }}', displayLegth: 999, timeRemaining: 1999}) </script>
                  <h3>Laravel 6 Flash Message Tutorial Step By Step</h3>
              </div>
              @endif
        @yield('content')    
    <footer>
        
    </footer>

</body>
</html>

welcome.blade.php

@extends('app')
 
@section('content')
 
<div class="col-lg-12">
<a href="/login"> <button class="btn form-main-control"> SignOut</button></a>
<a href="/delete"> <button class="btn form-main-control red"> Remove</button></a>
<a href="/cancel"> <button class="btn form-main-control yellow"> Exit</button></a>
<a href="/cancel"> <button class="btn form-main-control blue"> Edit</button></a>

</div>
 
@endsection

Web Programming Tutorials Example with Demo

Read :

Read Also:  Jquery Remove Duplicates from an array Examples

Summary

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

I hope you get an idea about laravel display flash message in view.
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.