0

I already create login function successfully, but the logout function it doesnt work!!! this is my code

logout in blade => <a href="{{ action('Auth\LoginController@getLogout')}}"> logout</a>

logout in Auth\LoginController.php=>

public function getLogout(){

    return redirect('login')->with(Auth::logout());
}

when i press the logout button, the browser will auto turn back to the home page.

In my code, it should be turn back to the login page, and it also not logout successfully.

Therefore, this function getLogout() it doesnt work!!!!

Have anyone know that? why it always turn the page to the Home ?

Zong
  • 71
  • 1
  • 1
  • 9
  • Possible duplicate of [How to logout and redirect to login page using Laravel 5.4?](https://stackoverflow.com/questions/43585416/how-to-logout-and-redirect-to-login-page-using-laravel-5-4) – sumit Mar 29 '18 at 00:36
  • What do you expect `->with(Auth::logout());` to do? `->with(..)` is used to pass variables to the view. Just put the `Auth::logout()` before the return statement. – DevK Mar 29 '18 at 00:39
  • look at the sample pages create by auth command, you need small form after your link to access logged user token. – mafortis Mar 29 '18 at 01:00
  • i find the reason in this case. In theAuth\LoginController.php , there have a code, and this code will turn the page to the middleware `public function __construct() { $this->middleware('guest')->except('logout'); }` just mark it, and the logout function will be work – Zong Mar 29 '18 at 01:07

1 Answers1

0

if you use php artisan make:Auth u can simply use this code to make logout link

<a href="{{url('/logout')}}">Logout </a> 

or u can use laravel logout button in default layout

<a class="dropdown-item" href="{{ route('logout') }}"
   onclick="event.preventDefault();
                 document.getElementById('logout-form').submit();">
    Logout
</a>

<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
    @csrf
</form>
Wahyu Fadzar
  • 116
  • 5