Laravel 5.1登录会话消息
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():
if (Auth::attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles)->withSuccess("message");
}
I've also tried adding to the 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. I use a partial called success.blade.php and the contents are:
@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.
我正在尝试在用户登录时添加会话成功消息。 p>
if(Auth :: attempt($ credentials,$ request-&gt;)( 'remember'))){
return $ this-&gt; handleUserWasAuthenticated($ request,$ throttles) - &gt; withSuccess(“message”);
}
code> pre>
我也尝试添加到handleUserWasAuthenticated(): p>
return redirect() - &gt; that($ this-&gt; redirectPath()) - &gt; withSuccess(“message”);
code> pre>
我在每次更改后运行composer dump-autoload,但它不会在视图中闪烁消息。 我使用了一个名为success.blade.php的部分,内容是: p>
@if(Session :: has('success'))
&lt; div class =“ alert alert-success“&gt;
&lt; button type =”button“class =”close“data-dismiss =”alert“&gt;&amp; times;&lt; / button&gt;
&lt; strong&gt;
&lt; i class =“fa fa-check-circle fa-lg fa-fw”&gt;&lt; / i&gt; 成功。 &amp; nbsp;
&lt; / strong&gt;
{{Session :: get('success')}}
&lt; / div&gt;
@ endif
code> pre>
\ n 我想我错过了一些东西,但我想不出什么,所以希望有一双新鲜的眼睛。 p>
提前谢谢。 p>
div>
Don't use ->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. To access the session manager, you can use the Request
object:
$request->session()->flash('success', 'Success message');
See http://laravel.com/docs/5.1/session#flash-data. You can also access the session manager using the Session
facade:
Session::flash('success', 'Success message');