Trọng Koy
Trọng Koy

Reputation: 21

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id'

I'm beginer in laravel. I have table tbl_user with user_id is pramary key.

User Model:

protected $table = 'tbl_user';
public $timestamps = false;

protected $fillable = [
    'user_id','name', 'email', 'password',
];
protected $primaryKey = 'user_id';
protected $hidden = [
    'password', 'remember_token',
];

When I checked user login by Auth:check() it show error message

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from tbl_user where id = 1 limit 1) (View: C:\xampp\htdocs\CMM\04.Development\resources\views\request\requestDetail.blade.php)

Upvotes: 0

Views: 2073

Answers (1)

Gaurav
Gaurav

Reputation: 1109

Change your SQL to

select * from tbl_user where user_id = 1 limit 1

You need to use user_id instead of ID in where clause as the table has column name user_id not id.

Upvotes: 0

Related Questions