我在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值。如何解决这个问题?
最佳答案
检查您的用户模型是否在$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'];
}
关于php - 为什么没有在Laravel中保存表单数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47996101/