9 months ago

Overriding Auth\LoginController

Posted 9 months ago by timgavin

I've overridden Laravel's default authentication by adding some of my own methods. However, I'm not sure the way I went about it is right.

Basically I added methods - such as the ones below - inside of App\Http\Controllers\Auth\LoginController

// allow login using either email or username
protected function credentials(Request $request)
    $usernameInput = trim($request->{$this->username()});
    $usernameColumn = filter_var($usernameInput, FILTER_VALIDATE_EMAIL) ? 'email' : $this->username();

    return [$usernameColumn => $usernameInput, 'password' => $request->password];

public function logout(Request $request)
    if (\Cookie::get('impersonate') === 'true') {


    return redirect('/');

Was this the correct way of doing it? I'm not so sure because the Laravel docs say I should create a LoginController at App\Http\Controllers\LoginController

I'm now trying to implement an intended login, to redirect the user back to a page after login, and every scenario I try is not working, the user is just directed to $redirectTo = '/home'.

Do I need to move my override methods into App\Http\Controllers\LoginController and return App\Http\Controllers\Auth\LoginController back to its default state?

What's the correct way of doing this?

Please sign in or create an account to participate in this conversation.