简体   繁体   中英

Modification in PostRegister Action Method - Laravel 5.1

I am using inbuilt Authentication System in laravel 5.1. I am trying to modify the PostRegister Action Method.

We can find the code in below mentioned path.

vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php

Can you suggest where should I do the modicications if I have to add one more field in User Table. I have already updated the migration file and database is updated also.

Open this file \\app\\Http\\Controllers\\Auth\\AuthController.php

Change you two methods like following:

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'new_field_name' => 'required|any_other_validation_if_needed',
        'password' => 'required|confirmed|min:6',
    ]);
}

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'db_column_name' => $data['new_field_name'], // it will more bug free if you use same db_column_name and new_field_name
        'password' => bcrypt($data['password']),
    ]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM