Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, October 14, 2016

Why does not work logout route in Laravel?

Why does not work logout route in Laravel?


When I try to logout from admin panel I get error:

MethodNotAllowedHttpException in RouteCollection.php line 218:  

But in routing there is route logout:

POST | logout |  App\Http\Controllers\Auth\LoginController@logout | web    

How can I fix this?

Answer by halloei for Why does not work logout route in Laravel?


You're trying to access a POST route with GET.

You could:
- create an ajax request with POST
- wrap the button in a POST-form
- create an additional GET-route to App\Http\Controllers\Auth\LoginController@logout

Answer by noodles_ftw for Why does not work logout route in Laravel?


You're doing a GET request to a POST route. Create or modify the existing route to accept GET requests (a redirect via a link is a GET request (most of the time))

Answer by Zaki Ahmed for Why does not work logout route in Laravel?


is your LoginController in Auth folder or Controllers folder.. Maybe You're giving a wrong path.. if the LoginController is in Controllers folder, the Path should be Route::get('logout', 'App\Http\Controllers\LoginController@logout');

Answer by maudev for Why does not work logout route in Laravel?


You need to do the following steps:

1.- if you're working with a class created by you to the login, specify it in config/auth.php:

'providers' => [      'users' => [          'driver' => 'eloquent',          'model' => App\Administrator::class,      ],  ],  

2.- your model must inherit from class Authenticatable:

use Illuminate\Foundation\Auth\User as Authenticatable;  class Administrator extends Authenticatable{      #code...  }  

3.- add the logout() function on your LoginController, import Auth and Redirect classes

public function logout(){      Auth::logout();      return Redirect::to('admin');  }  

3.- specify the route that you will use to logout via GET

Route::get('logout','LoginController@logout');  

It is all, this should work.

NOTE: Check if you are authenticated by the function Auth::check()

Additional information: When you are working with POST requests, Laravel needs to verify that the request are not a malicious request, for this Laravel needs an ecrypted code, this is called csrf_token, if you don't send this, by default all your requests will be not allowed.

Answer by MECU for Why does not work logout route in Laravel?


If you have upgraded to Laravel 5.3, the get logout route was purposefully removed during the upgrade.

POST To Logout

The Auth::routes method now registers a POST route for /logout instead of a GET route. This prevents other web applications from logging your users out of your application. To upgrade, you should either convert your logout requests to use the POST verb or register your own GET route for the /logout URI

https://laravel.com/docs/5.3/upgrade

You need to change the have all logout links to forms so it can POST to the route. From https://github.com/acacha/adminlte-laravel/issues/94, something like:

 Logout       

Source

Answer by Deepak for Why does not work logout route in Laravel?


Replace

{{ trans('adminlte_lang::message.signout') }}  

with

 {{ trans('adminlte_lang::message.signout') }}       

in mainheader.blade.php and it will fix.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.