我正在尝试在用户登录时添加会话成功消息。
我尝试将以下内容添加到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
我觉得我错过了一些东西,但我想不出什么,所以希望有一双新鲜的眼睛。
提前谢谢。
答案 0 :(得分:3)
请勿使用->withSuccess()
。
使用->with('success', 'Success message')
中所述的Request
,或使用会话管理器。要访问会话管理器,您可以使用$request->session()->flash('success', 'Success message');
对象:
Session
见http://laravel.com/docs/5.1/responses#redirecting-with-flashed-session-data。您还可以使用Session::flash('success', 'Success message');
facade:
num