I'm solving quite strange problem:
I try to log in user, if credentials are incorrect, I flash message into Session and redirect user bach to login page. There is shown message, which was flashed into session. Anyway, after I do reload of the page, there is still message in the Session, however, it should disappear.
Could you provide me your help? Here is my code, where I flash message into session:
public static function verify($email, $password) {
$verified = Auth::user()->attempt([
'email' => $email,
'password' => $password
]);
if($verified) {
$user = Auth::user()->get();
Session::flash('message', [
'title' => trans('user.logged_in'.($user->sex != null ? '_'.$user->sex : '')),
'status' => 'success'
]);
return redirect(route('adminDashboard'));
}
else {
Session::flash('message', [
'title' => trans('user.bad_credentials'),
'status' => 'error'
]);
return redirect()->back();
}
return $verified;
}
Here is code of page, which is shown on address, where I redirect, after incorrect credentials (redirect()->back()
)
@if(Session::has('message'))
<?php
$message = Session::get('message');
$status = isset($message['status']) ? $message['status'] : 'success';
$messageString = '';
if(isset($message['title']) && $message['title'] != '')
$messageString = '"'.$message['title'].'"';
if(isset($message['text']) && $message['text'] != '')
$messageString .= ($messageString != '' ? ',' : '').'"'.$message['text'].'"';
?>
<script>
$(document).ready(function () {
Notify({!! $messageString !!}).{{ $status }}();
});
</script>
@endif
I'm quite confused about this behaviour. I also tried to manually call Session::forget('message')
in View, after I show the message, but message disappeared from session, if I immediately after this print Session::all(), but after I did reload, message was again in Session.
Thank you very much for your help.