[英]Laravel 5.1 Login Session Message
我正在尝试在用户登录时添加会话成功消息。
我已经尝试将以下内容添加到AuthenticatesUsers.php trait postLogin()中:
if (Auth::attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles)->withSuccess("message");
}
我也尝试添加到handleUserWasAuthenticated():
return redirect()->intended($this->redirectPath())->withSuccess("message");
我在每次更改后运行composer dump-autoload,但它不会在视图中闪烁消息。 我使用了一个名为success.blade.php的部分,内容如下:
@if (Session::has('success'))
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>
<i class="fa fa-check-circle fa-lg fa-fw"></i> Success.
</strong>
{{ Session::get('success') }}
</div>
@endif
我想我错过了一些东西,但我想不出什么,所以希望有一双新鲜的眼睛。
先感谢您。
不要使用->withSuccess()
。
使用->with('success', 'Success message')
,如http://laravel.com/docs/5.1/responses#redirecting-with-flashed-session-data中所述 ,或使用会话管理器。 要访问会话管理器,您可以使用Request
对象:
$request->session()->flash('success', 'Success message');
见http://laravel.com/docs/5.1/session#flash-data 。 您还可以使用Session
Facade访问会话管理器:
Session::flash('success', 'Success message');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.