Flash message not working in laravel 5.2

Slillz

I'm trying to get flash messaging to work in Laravel 5.2. Everything seems to be correct but when I go to /alert nothing happens. Any suggestions?

The following is my routes.php..

  Route::group(['middleware' => ['web']], function(){
  Route::get('/', [
    'uses' => 'HomeController@index',
    'as' => 'welcome',
    ]);

  Route::get('/alert', function()
  {
    return redirect()->route('welcome')->with('info', 'You have signed up!');
  });
});

The following is my alerts.blade.php...

 @if (Session::has('info'))
<div class="alert">
     {{ Session::get('info') }}
</div>
@endif

The following is my master.blade.php..

<!DOCTYPE html>
<html>
<head>
   <title>@yield('title')</title>
   <link rel="stylesheet"              href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

</head>

<body>
   @include('includes.header')
   <div class="container">
     @yield('content')
     @include('includes.alerts')
    </div>
 </body>
</html>
David Lavieri

You should try to use as the documentation suggest instead of using the facade \Session

From documentation:

Of course, after the user is redirected to a new page, you may retrieve and display the flashed message from the session. For example, using Blade syntax:

@if (session('info'))
<div class="alert">
    {{ session('info') }}
</div>
@endif

Your code work fine on my laravel 5.2 using the syntax above.

EDIT:

they use return redirect('dashboard')->with('status', 'Profile updated!');

they don't use the method redirect()->route()

try to use this instead:

Route::get('/alert', function(\Illuminate\Http\Request $request)
{
    $request->session()->flash('info', 'You have signed up!');
    return redirect()->route('welcome');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Laravel 4 - Redirect with flash message not working

From Dev

Laravel 5 Fundamentals: Flash Messaging Timer not working

From Dev

Redirecting with a message not working in Laravel 5

From Dev

Redirecting with a message not working in Laravel 5

From Dev

Flash message not working in octobercms

From Dev

In Laravel 5, How to customize Session flash message with href

From Dev

Flash data in Laravel 5

From Dev

Flash data in Laravel 5

From Dev

laravel how to display flash message with confirm message

From Dev

Laravel 5 flash message flashes again after navigating away and using back button

From Dev

Email validation flash message not working properly

From Dev

Flash Message in cakephp 3 it doesn't working

From Dev

Alert flash message not working with respond_with

From Dev

flash[:alert] not working, but flash[:notice] displays the message on redirect

From Dev

flash[:alert] not working, but flash[:notice] displays the message on redirect

From Dev

I am using laravel 5. I am using flash messaging, it is not working

From Dev

Setting display time of flash message in laravel 4.2

From Dev

How to include html tags to laravel flash message?

From Dev

Setting display time of flash message in laravel 4.2

From Dev

Laravel flash message showing after refresh

From Dev

Laravel 5 redirect with message

From Dev

Timing message in laravel 5

From Dev

flash session not working in Middleware Laravel 5.2

From Dev

How to set a flash message in Yii2?

From Dev

Returning laravel 5 flash data in view page

From Dev

Trying to make a paragraph break in a flash message with \n not working

From Dev

Laravel 5 logout is not working

From Dev

PHPUnit not working with Laravel 5

From Dev

orderBy is not working in Laravel 5

Related Related

  1. 1

    Laravel 4 - Redirect with flash message not working

  2. 2

    Laravel 5 Fundamentals: Flash Messaging Timer not working

  3. 3

    Redirecting with a message not working in Laravel 5

  4. 4

    Redirecting with a message not working in Laravel 5

  5. 5

    Flash message not working in octobercms

  6. 6

    In Laravel 5, How to customize Session flash message with href

  7. 7

    Flash data in Laravel 5

  8. 8

    Flash data in Laravel 5

  9. 9

    laravel how to display flash message with confirm message

  10. 10

    Laravel 5 flash message flashes again after navigating away and using back button

  11. 11

    Email validation flash message not working properly

  12. 12

    Flash Message in cakephp 3 it doesn't working

  13. 13

    Alert flash message not working with respond_with

  14. 14

    flash[:alert] not working, but flash[:notice] displays the message on redirect

  15. 15

    flash[:alert] not working, but flash[:notice] displays the message on redirect

  16. 16

    I am using laravel 5. I am using flash messaging, it is not working

  17. 17

    Setting display time of flash message in laravel 4.2

  18. 18

    How to include html tags to laravel flash message?

  19. 19

    Setting display time of flash message in laravel 4.2

  20. 20

    Laravel flash message showing after refresh

  21. 21

    Laravel 5 redirect with message

  22. 22

    Timing message in laravel 5

  23. 23

    flash session not working in Middleware Laravel 5.2

  24. 24

    How to set a flash message in Yii2?

  25. 25

    Returning laravel 5 flash data in view page

  26. 26

    Trying to make a paragraph break in a flash message with \n not working

  27. 27

    Laravel 5 logout is not working

  28. 28

    PHPUnit not working with Laravel 5

  29. 29

    orderBy is not working in Laravel 5

HotTag

Archive