0
我在我的註冊表中添加了幾個新字段。除自定義字段外,所有默認字段都存儲在數據庫中。如何在laravel中存儲自定義註冊字段?
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
'company_name' => 'required',
]);
}
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'company_name' => $data['company_name'],
'role' => 'client',
]);
return $user;
}
這裏是我的形式
<form action="/register" method = "post" id = "reg_form">
{{csrf_field()}}
<div class="form-group">
<input type="text" name="name" id="name" placeholder="Name"/>
</div>
<div class="form-group">
<input type="email" name="email" id="email" placeholder="Email"/>
</div>
<div class="form-group">
<input type="text" name="company_name" id="email" placeholder="Name of your Company"/>
</div>
<div class="form-group">
<input type="password" name="password" id="pass" placeholder="Password"/>
</div>
<div class="form-group">
<input type="password" name="password_confirmation" id="re_pass" placeholder="Re enter password"/>
</div>
<div class="form-group">
<input type="submit" class="btn" id="register_sbt_btn" value="Register"/>
</div>
</div>
</form>
的company_name
和role
沒有得到保存。無論何時註冊新用戶,我都會給role => client
一個默認值。