How can I change Laravel default authentication user table to my table. After that forget password reset, reset mail should work perfectly
My table structure like
username (email), password, lastlogin, remember_token, role_id
How can I change Laravel default authentication user table to my table. After that forget password reset, reset mail should work perfectly
My table structure like
username (email), password, lastlogin, remember_token, role_id
As Per Laravel Discussion Thread :
Have a look at the file
config/auth.php
. You'll find the name of the table in there:'table' => 'users',
change your User.php
model adding protected $table = 'your_table_name'
even with protected $primaryKey = 'user_id'
if needed
Change the table information in config/auth.php
.
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
As for changing the email
field to username
, the built in auth would break. You need to make changes to almost all the default auth controllers in app/Http/Controllers/Auth
. You may need to extend some methods to override them to use username
. For instance RegisterController
is simple. You just need to edit the validator and create methods. Where as the other controllers use traits which you need to explore to extract the methods that has to be changed to make the username
field work.