laravel 5 built in scaffolding tried to use username instead of email error

Juliver Galleto

I already created a column username and fill it in the users table that was used with the laravel 5 built in login scaffolding and what I'm trying to do is to use username instead of the default email so I tweak the code that I found in laravel\vendor\compiled.php with the following (refer below)

this default code

public function postLogin(Request $request)
{
    $this->validate($request, array('email' => 'required|email', 'password' => 'required'));
    $credentials = $request->only('email', 'password');
    if ($this->auth->attempt($credentials, $request->has('remember'))) {
        return redirect()->intended($this->redirectPath());
    }
    return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
}

to

public function postLogin(Request $request)
{
    $this->validate($request, array('email' => 'required', 'password' => 'required'));
    if ($this->auth->attempt(['username' =>  $request->input('email'), 'password' =>  $request->input('password'), $request->has('remember')])) {
        return redirect()->intended($this->redirectPath());
    }
    return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
}

but it give me an error saying

QueryException in Connection.php line 620: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from dodong_users where username = [email protected] and 0 = 0 limit 1)

any help, suggestion, recommendation, clues, ideas to fix this so that I could login with username instead of email would be greatly appreciated. Thank you!

ntzm

Change this:

if ($this->auth->attempt(['username' =>  $request->input('email'), 'password' =>  $request->input('password'), $request->has('remember')])) {

To this:

if ($this->auth->attempt(['username' =>  $request->input('email'), 'password' =>  $request->input('password')], $request->has('remember'))) {

Looks like you just put $request->has('remember') in the wrong place. It was looking for a column called 0 because you passed the value of $request->has('remember') as part of the attempt() data.

To use an example from the documentation, you were doing this:

if (Auth::attempt(['email' => $email, 'password' => $password, $remember]))
{
    // The user is being remembered...
}

When you should have been doing this:

if (Auth::attempt(['email' => $email, 'password' => $password], $remember))
{
    // The user is being remembered...
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

modify laravel 5.1 login to use username instead of email

From Dev

Laravel 5 - how to use basic auth with username in place of email?

From Dev

Username instead Email for RegisterViewModel MVC5

From Dev

Laravel Login using email instead of username

From Dev

Laravel Login using email instead of username

From Dev

Authentication using username instead of email laravel 5.2

From Dev

Use Username instead of Email for identity in Asp.net mvc5

From Dev

Laravel 4 Auth wrong username or email error

From Dev

Username authentication instead of email

From Dev

How can I use the email instead of the username in LDAP authentication with PHP?

From Dev

How can I use the email instead of the username in LDAP authentication with PHP?

From Dev

Laravel 5 custom login with username OR email using the Attempt method

From Dev

JWTAuth authentication with username instead of email

From Dev

Grail's Spring security: Use email instead of username to switch users in SwitchUserFilter

From Dev

How to use phonenumber instead email when authenticating in Laravel 5.2?

From Dev

Use of + or . in the username part of email addresses

From Dev

OAuth2: authenticate with email instead of username

From Dev

How to login with "UserName" instead of "Email" in MVC Identity?

From Dev

How to log in by email instead of username in Spring security

From Dev

What does scaffolding mean in Laravel 5?

From Dev

Can I use the browsers built in HTML5 email validation in JS?

From Dev

Built a gem but when tried it gives an error that command not found

From Dev

Change MVC5 scaffolding to bootstrap table instead of data list

From Dev

Laravel 5.2 : Password reset email against username

From Dev

Laravel 5.2 : Password reset email against username

From Dev

Scaffolding with Laravel

From Dev

Laravel 5: Sending Email

From Dev

LARAVEL 5 :: Display 'username' on homepage?

From Dev

Php Checking for username and Email (Internal server error)

Related Related

  1. 1

    modify laravel 5.1 login to use username instead of email

  2. 2

    Laravel 5 - how to use basic auth with username in place of email?

  3. 3

    Username instead Email for RegisterViewModel MVC5

  4. 4

    Laravel Login using email instead of username

  5. 5

    Laravel Login using email instead of username

  6. 6

    Authentication using username instead of email laravel 5.2

  7. 7

    Use Username instead of Email for identity in Asp.net mvc5

  8. 8

    Laravel 4 Auth wrong username or email error

  9. 9

    Username authentication instead of email

  10. 10

    How can I use the email instead of the username in LDAP authentication with PHP?

  11. 11

    How can I use the email instead of the username in LDAP authentication with PHP?

  12. 12

    Laravel 5 custom login with username OR email using the Attempt method

  13. 13

    JWTAuth authentication with username instead of email

  14. 14

    Grail's Spring security: Use email instead of username to switch users in SwitchUserFilter

  15. 15

    How to use phonenumber instead email when authenticating in Laravel 5.2?

  16. 16

    Use of + or . in the username part of email addresses

  17. 17

    OAuth2: authenticate with email instead of username

  18. 18

    How to login with "UserName" instead of "Email" in MVC Identity?

  19. 19

    How to log in by email instead of username in Spring security

  20. 20

    What does scaffolding mean in Laravel 5?

  21. 21

    Can I use the browsers built in HTML5 email validation in JS?

  22. 22

    Built a gem but when tried it gives an error that command not found

  23. 23

    Change MVC5 scaffolding to bootstrap table instead of data list

  24. 24

    Laravel 5.2 : Password reset email against username

  25. 25

    Laravel 5.2 : Password reset email against username

  26. 26

    Scaffolding with Laravel

  27. 27

    Laravel 5: Sending Email

  28. 28

    LARAVEL 5 :: Display 'username' on homepage?

  29. 29

    Php Checking for username and Email (Internal server error)

HotTag

Archive