JuNas
JuNas

Reputation: 482

Laravel auth cannot logout and User session always filled

I use default auth from Laravel 5.7, and make some changes to the login page display. I have logged in several times and can run normally, after I stayed a day, and I opened my app again, I found a problem, where the user I last used was still logged in (no logout / user session remained), even though already restarted. when I try to logout (using the logout function) it can get an error

MethodNotAllowedHttpException
No message

I'm not sure, is this a bug from the "Remember me" feature or not. I have been looking for a solution, but I didn't find it, maybe because of my incorrect query.

Logout function error logout function

My login form login form

this is my route my route

route list 1 route list

route list

route list 2

Upvotes: 1

Views: 1258

Answers (1)

localroot
localroot

Reputation: 556

Laravel 5.4+ uses post method for logout so instead of simple url (get) request you should post a form to logout.

Try Something Like this

<a href="#" onclick="document.getElementById('logout-form').submit();"> Logout</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
    {{ csrf_field() }}
</form>

Upvotes: 2

Related Questions