[5.3] Login via email OR username

Posted 2 years ago by 2Pr3cise

Hi everyone,

In my application, I want to be able to login in either with my username or my email address (thus, I added a username column to the schema).

I tried to set up the LoginController like this, which did not work ...

public function username()
{
    $login = request('login');
    return filter_var( $login, FILTER_VALIDATE_EMAIL ) ? 'email' : 'username';
}

protected function validateLogin(Request $request)
{
    $this->validate($request, [
        'login' => 'required', 'password' => 'required',
    ]);
}

My login form contains the inputs login (which is the email or the username) and a password input.

... I think I need to implement something more. Can you help me?

Thanks in advance!!

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.