Laravel 5.1 Session message
I am trying to add a successful session message when a user logs in.
I tried adding the following to the AuthenticatesUsers.php postLogin () trait:
if (Auth::attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles)->withSuccess("message");
}
I also tried adding to handleUserWasAuthenticated ():
return redirect()->intended($this->redirectPath())->withSuccess("message");
I run the dump-autoload linker after every change, but it just won't flash a message in the view. I am using partially called success.blade.php and the content is:
@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 I'm hoping so much for a fresh set of eyes at this point.
Thanks in advance.
source to share
Do not use ->withSuccess()
.
Use ->with('success', 'Success message')
as described at http://laravel.com/docs/5.1/responses#redirecting-with-flashed-session-data , or use a session manager. To access the session manager, you can use an object Request
:
$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 facade Session
:
Session::flash('success', 'Success message');
source to share