闪存消息在 laravel 5.2 中不起作用


Flash message not working in laravel 5.2

我正在尝试让闪存在Laravel 5.2中工作。一切似乎都是正确的,但是当我转到/alert时,什么也没发生。有什么建议吗?

以下是我的路线.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!');
  });
});

以下是我的警报.blade.php...

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

以下是我的主人.刀片.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>

您应该尝试按照文档建议使用,而不是使用外观 ''Session

从文档:

当然,在用户被重定向到新页面后,您可以从会话中检索并显示闪烁的消息。例如,使用刀片语法:

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

使用上面的语法,您的代码在我的 laravel 5.2 上运行良好。

编辑:

他们使用return redirect('dashboard')->with('status', 'Profile updated!');

他们不使用该方法redirect()->route()

尝试改用它:

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