dongtong5242 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>
        <strong>
            <i class="fa fa-check-circle fa-lg fa-fw"></i> Success. &nbsp;
        </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.

  • 写回答

1条回答 默认 最新

  • doulin6761 2015-07-18 23:00
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题