[英]Laravel 5.1 Login Session Message
I'm trying to add a Session success message when a User login. 我正在尝试在用户登录时添加会话成功消息。
I've tried adding the following to the AuthenticatesUsers.php trait postLogin(): 我已经尝试将以下内容添加到AuthenticatesUsers.php trait postLogin()中:
if (Auth::attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles)->withSuccess("message");
}
I've also tried adding to the handleUserWasAuthenticated(): 我也尝试添加到handleUserWasAuthenticated():
return redirect()->intended($this->redirectPath())->withSuccess("message");
I run composer dump-autoload after each change but it just will not flash the message in the view. 我在每次更改后运行composer dump-autoload,但它不会在视图中闪烁消息。 I use a partial called success.blade.php and the contents are:
我使用了一个名为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
I think I'm missing something but I can't think what at the moment so hoping for a fresh set of eyes. 我想我错过了一些东西,但我想不出什么,所以希望有一双新鲜的眼睛。
Thank you in advance. 先感谢您。
Don't use ->withSuccess()
. 不要使用
->withSuccess()
。
Use ->with('success', 'Success message')
, as described in http://laravel.com/docs/5.1/responses#redirecting-with-flashed-session-data , or use the session manager. 使用
->with('success', 'Success message')
,如http://laravel.com/docs/5.1/responses#redirecting-with-flashed-session-data中所述 ,或使用会话管理器。 To access the session manager, you can use the Request
object: 要访问会话管理器,您可以使用
Request
对象:
$request->session()->flash('success', 'Success message');
See http://laravel.com/docs/5.1/session#flash-data . 见http://laravel.com/docs/5.1/session#flash-data 。 You can also access the session manager using the
Session
facade: 您还可以使用
Session
Facade访问会话管理器:
Session::flash('success', 'Success message');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.