How to write text in one database column for each new user when registering in Laravel 5.2?

I am using the Laravel 5.2 Auth function and registration is working fine.

Now I need to write a row in a special column in the user table during registration. This is not the value from the input of an HTML form. This is static text describing the role of the user (contributor). All registered users should receive the value "contributor" in the user_role column. I tried to achieve this by adding this line to AuthController.php:

'user_role' => 'contributor',

The whole function of adding values ​​to the database is as follows:

/**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'user_role' => 'contributor',
        ]);
    }

, , 'user_role' => 'contributor',.
"" user_role?
, $data?

+4
1

user_role $fillable ?

,

protected $fillable = ['name', 'email', 'password', 'user_role'];
+3

Source: https://habr.com/ru/post/1652477/


All Articles