1
votes

app/Http/Controllers/Auth/LoginController.php

In my app folder I have a LoginController which I override the logout function to add a session flash:

public function logout(Request $request)
{
    $this->guard()->logout();

    $request->session()->flush();

    $request->session()->regenerate();
    $request->session()->flash('status', 'Task was successful!');

    error_log('~~~~~~~~~~~~~~~~~~~~~');
    error_log($request->session()->get('status'));
    error_log('~~~~~~~~~~~~~~~~~~~~~');

    return redirect('/');
}

My error log works here, but when I actually get redirected it goes to routes/web.php line:

Route::get('/', 'HomeController@index');

But at this point the session no longer seems to exist. My end goal was to display it on my login page that the user has successfully logged out. I have a feeling my logic is flawed and it's being erased via the routes file, but I know at some point I am indeed writing to the session. Any Advice?

3
have you tried this approach? return redirect('/')->withStatus('Task was sucessful!'); - manix
return redirect('/login'); stops me from going to the route redirect and lets me flash to my login. This is going to be my solution but I wish I knew how to keep the flash during the route redirect (if even possible) - Lucas SenCab A Ugh

3 Answers

1
votes

in my case i just use

Session::flash('message','User Just Logout');
Session::flash('alert','alert-danger');

and i use this code to get my message on blade template file

@if(Session::has('message'))
  <p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p>
@endif

and i still can use that function to give alert to all my route without error

0
votes

Try this

    public function logout(){
    //Illuminate\Support\Facades\Auth::logout();
    Auth::logout();
    flash()->info('Bye', 'You have been successfully logged out!');
    return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
0
votes

when you logout your session expires and so the session flash message not showing... so you have to use the flash message with out session... use another approach for displaying flash message.