laravel 5.4 change authentication users table name

拟墨画扇 提交于 2019-11-30 07:32:19

You can change the table name in the migration file and then change the table name variable in the User.php model.

Example:

class Flight extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'my_flights';
}

https://laravel.com/docs/5.4/eloquent#eloquent-model-conventions

You need just change in two places

1.add this line after hidden array of app/User.php

 protected $hidden = [
    'password', 'remember_token',
];

protected $table = 'another_table_name';

2.In the RegisterController change the table name in the validator method:

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:another_table_name',
        'password' => 'required|string|min:6|confirmed',
    ]);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!