繁体   English   中英

Flash消息在laravel 5.2中不起作用

[英]Flash message not working in laravel 5.2

我正试图让Flash消息在Laravel 5.2中运行。 一切似乎都是正确的,但当我去/警报没有任何反应。 有什么建议?

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

以下是我的alerts.blade.php ...

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

以下是我的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>

您应该尝试使用文档建议而不是使用facade \\ Session

来自文档

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

@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');
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM