laravel 5.4 change authentication users table name

前端 未结 2 1231
傲寒
傲寒 2020-12-29 15:15

I\'m currently using the laarvel5.4 authentication in my application; and I want to change the users table name while keeping its role as it is in the authe

相关标签:
2条回答
  • 2020-12-29 16:06

    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

    0 讨论(0)
  • 2020-12-29 16:07

    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',
        ]);
    }
    
    0 讨论(0)
提交回复
热议问题