0

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

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93

3 Answers3

1

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',
LuFFy
  • 8,799
  • 10
  • 41
  • 59
  • @SusantaKumarDas, if you have find your answer, you can post correct answer and accept it yourself. – LuFFy May 23 '17 at 12:18
0

change your User.php model adding protected $table = 'your_table_name' even with protected $primaryKey = 'user_id' if needed

Alex
  • 566
  • 3
  • 15
0

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.

Sandeesh
  • 11,486
  • 3
  • 31
  • 42
  • login & register working. but after login i want set last login date. forget password & reset not working – Susanta Kumar Das May 23 '17 at 10:10
  • @you need to make the appropriate changes in the controller then. You can't expect people to do all the work for you. At least make an effort. – Sandeesh May 23 '17 at 10:11