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.
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');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.