为用户填写额外的列
Fill extra column for User
我有一个 user
table 和一个 referral
列,这个代码在 controller/auth
:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'referral' => md5($data['email']),
]);
}
它添加了 name
、email
和 password
但不是 referral
。
没有错误或通知。我还应该如何填充 referral
列?
打开您的 User
模型(可能 app/User.php
,然后更改:
protected $fillable = [
'name', 'email', 'password',
];
进入
protected $fillable = [
'name', 'email', 'password', 'referral'
];
您需要将列添加到 fillable 以保存它。
我有一个 user
table 和一个 referral
列,这个代码在 controller/auth
:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'referral' => md5($data['email']),
]);
}
它添加了 name
、email
和 password
但不是 referral
。
没有错误或通知。我还应该如何填充 referral
列?
打开您的 User
模型(可能 app/User.php
,然后更改:
protected $fillable = [
'name', 'email', 'password',
];
进入
protected $fillable = [
'name', 'email', 'password', 'referral'
];
您需要将列添加到 fillable 以保存它。