我在My laravel应用程序中使用Auth:命令寄存器表单。我已经将新的nic输入框添加到register.blade.php文件中, register.blade.php
<div class="form-group{{ $errors->has('nic') ? ' has-error' : '' }}">
<label for="nic" class="col-md-4 control-label">NIC</label>
<div class="col-md-6">
<input id="nic" type="text" class="form-control" name="nic">
@if ($errors->has('nic'))
<span class="help-block">
<strong>{{ $errors->first('nic') }}</strong>
</span>
@endif
</div>
</div>
和我的AuthController是这样的,
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
'nic' => 'required|min:10',
]);
}
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'nic' => $data['nic'],
]);
}
我在Users表中也有新列 nic 。但是当我点击注册按钮时,其他数据值在用户表中保存得很好,但是nic列没有保存nic值。怎么能解决这个问题?
答案 0 :(得分:1)
检查您的用户模型是否在$fillable
数组中添加了nic,因为您执行了mass assignement
<?php
namespace App;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Backpack\Base\app\Notifications\ResetPasswordNotification as ResetPasswordNotification;
class User extends Authenticatable
{
use Notifiable;
protected $fillable = ['username', 'email', 'password', 'nic'];
}