Dibyaranjan Dibyaranjan - 1 month ago 7
PHP Question

Laravel change id column to userId in users table

i am trying to change the id of users table to userId, but laravel authentication mechanism always checks for id column of users table.like


Users::check() and Users::attempt()


these functions always check for id attribute of users table, how to change this behavior of laravel.

Answer

To override the primary key used to search you must define the primaryKey property on the User model.

protected $primaryKey = 'userId';
Comments