Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to logout with a GET request in Laravel

I am getting error when i am logout, it's showing me this error..."The GET method is not supported for this route. Supported methods: POST." Please help me to solve this issue..

Here are my code...

@if(Auth::check())
  <li><i class="fa fa-user"></i> {{Auth::user()->name}}:
    <a href="{{url('logout')}}">logout</a>
  </li>
@else
  <li>
    <a href="{{route('login')}}"><i class="fa fa-user"></i>Login</a>
  </li>
@endif
like image 737
sumit group3 Avatar asked Oct 10 '19 06:10

sumit group3


People also ask

What is Auth :: logout () in laravel?

In my previous post, we implement the authentication, now we will talk about Laravel auth logout. Logout is one of the important functionality to implement in a web application when users log in they should have an option to log out of their account and secure it.

How do I manually logout of laravel?

To manually log users out of your application, you may use the logout method provided by the Auth facade. This will remove the authentication information from the user's session so that subsequent requests are not authenticated.

How do I change the logout of a route in laravel?

How do I change the logout of a route in Laravel? Add a custom logout route in Auth/LoginController, call Auth::logout() and return redirect to your path, or. Add an after-middleware (say redirectAfterLogout) and add it to the logout route.


1 Answers

You could just add this line in your web.php routes file:

Route::get('/logout', 'Auth\LoginController@logout');

This allows you to logout by using a GET Request.

like image 154
thmspl Avatar answered Oct 09 '22 14:10

thmspl