2015-07-18 22:09
浏览 52

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">&times;</button>
            <i class="fa fa-check-circle fa-lg fa-fw"></i> Success. &nbsp;
        {{ Session::get('success') }}

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.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试在用户登录时添加会话成功消息。 < 我尝试将以下内容添加到AuthenticatesUsers.php trait postLogin()中:

  if(Auth :: attempt($ credentials,$ request-&gt;)(  'remember'))){
 return $ this-&gt; handleUserWasAuthenticated($ request,$ throttles) - &gt; withSuccess(“message”); 


  return redirect() - &gt; that($ this-&gt; redirectPath()) - &gt;  withSuccess(“message”); 

我在每次更改后运行composer dump-autoload,但它不会在视图中闪烁消息。 我使用了一个名为success.blade.php的部分,内容是:

  @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 
 \  n 



  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulin6761 2015-07-18 23:00

    Don't use ->withSuccess().

    Use ->with('success', 'Success message'), as described in, or use the session manager. To access the session manager, you can use the Request object:

    $request->session()->flash('success', 'Success message');

    See You can also access the session manager using the Session facade:

    Session::flash('success', 'Success message');
    点赞 评论

相关推荐 更多相似问题