Laravel change default primary key of users table

user7098129

I am trying to change the default primary key from id of users table to userId, but Laravel authentication mechanism always checks for id from users table. Example:

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

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

Dinanath Thakur

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

protected $primaryKey = 'userId';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Change default primary key in Eloquent

Laravel - store the value of primary key from persons table in the foreign key of users table

Change primary key in PostgreSQL table

Change table users in laravel 5.5

Postgres: change primary key in existing table

spatie/laravel-medialibrary change primary key

Unable to create or change a table without a primary key - Laravel DigitalOcean Managed Database

laravel 5 belongsToMany using primary key as table

The column in table 'Users' do not match an existing primary key or unique constraint

ArgumentError: Mapper mapped class Users->users could not assemble any primary key columns for mapped table 'users'

Setting Default Value for Primary Key in Laravel Migration for sqlite

Primary Key is different from the default id that laravel searches for

Laravel 5.2 auth change 'users' table

laravel 5.4 change authentication users table name

Laravel : How can I change default indexing key length in morph table

Mapper Mapper|User|users could not assemble any primary key columns for mapped table 'users'

Laravel Model primary key change error Illegal offset type

Default create_users_table throwing max key length error

change primary key values

Laravel migrate creating table with more than one primary key

How to save primary key to another table as FK in laravel 5.5

Set Primary Key for Table?

Table without a primary key

Laravel - Multiple primary key

Laravel 5.3 Passport migrations & modifying the default users table

Primary Key and Foreign Key on Laravel

MySql - Is primary key unique by default?

primary key column not visible by default

Default value with primary key sqlalchemy