1

I'am using authentification in my Laravel 5.2 application. All ok, but logout not working. Can anyone explain to me, why it happend?

routes.php

Route::group([

    'middleware' => ['web']

], function () {

        Route::get('auth/login', 'Auth\AuthController@getLogin');
        Route::post('auth/login', 'Auth\AuthController@postLogin');
        Route::get('auth/logout', 'Auth\AuthController@getLogout');
        ...
});

Controller.php

class AuthController extends Controller
{
    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout', 'getLogout']);
    }

    public function logout()
    {
        /* This place not trigger */
        echo 'Logout';
        exit;

        Auth::guard($this->getGuard())->logout();

        return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
    }
    ...
}

1 Answer 1

3

Hope this is work

You make a mistake in the method name of the controller.

1)

  public function logout()

Replace with this method

 public function getLogout()

Explanation ----------------------------------------

In route you used following route

Auth\AuthController@getLogout

And you used a Method following

public function logout()

method name is only logout and route has getLogout so the this method not find in the Auth controller so logout not working.


2) Another way is use this only.

public function __construct()
{
    $this->middleware('guest', ['except' => 'getLogout']);          
}

And Remove the Logout method.

Thnaks

Sign up to request clarification or add additional context in comments.

1 Comment

You right of course, thanks. But some addition, this line must be such as $this->middleware('guest', ['except' => ['logout', 'getLogout']]);.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.