0

So I'm trying to make an account-based website using Laravel 5.5.

I have a database table 'users' where it has:

id - int(10)[PRIMARY_KEY],

created_at - timestamp,

updated_at - timestamp,

username - varchar [FOREIGN_KEY]

password - varchar

I already have username and password in my database

username: vanderozili

password: jaujaujau

when i'm trying to login using this validation

$validation = Validator::make( $request->all(), [
                'username' => 'username|required',
                'password' => 'required|min:8'
            ]);

            if(Auth::attempt(['username', $request->input('username'), 'password', $request->input('password')])){
                return redirect('/shop');
            }

            return redirect()->back();
        }

I'm encountering this error.

(2/2) QueryException

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from users where 0 = username and 1 = vanderozili and 2 = password and 3 = jaujaujau limit 1)

I'm using mysql thru phpmyadmin

I already searched it online but I can't see a similar problem as I'm experiencing. What seems to be the problem?

1 Answers1

1

This args should be an associative array of column name/value pairs, not a simple series of array values:

if(Auth::attempt(['username' => $request->input('username'), 'password' => $request->input('password')])){`

as shown in the Laravel Docs

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • Thanks for your answer, sir. But I would like to clarify if I should also include the id inside the Auth::attempt? – jaucabiles Oct 16 '17 at 17:13
  • Why do you need to include the id in the Auth Attempt? the entered username should be sufficient and unique to identify the user account – Mark Baker Oct 16 '17 at 17:14
  • oh sorry. I didn't read the 'associative array of column' part. so sir, if I use this if (Auth::attempt(['username' => $username, 'password' => $password])) instead of what I've been used it will work right? – jaucabiles Oct 16 '17 at 17:20