我使用name = fullname将标签输入添加到表单中,但是出现错误;它说“字段'全名'没有默认值。”我的代码有问题吗?
我在标签输入中添加了属性名称,但仍然无法使用
{!! Form::open(['route' => 'users.store']) !!}
<div class="row">
<div class="col-25">
<label>Unit Name</label>
</div>
<div class="col-75">
{!! Form::select('division', $divisions, null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="row">
<div class="col-25">
<label>Full Name</label>
</div>
<div class="col-75">
<input type="text" name="fullname" aria-label="fullname" autocomplete="off">
</div>
</div>
<div class="row">
<div class="col-25">
<label>Username</label>
</div>
<div class="col-75">
<input type="text" name="username" aria-label="username"" autocomplete="off">
</div>
</div>
<div class="row">
<div class="col-25">
<label>Password</label>
</div>
<div class="col-75">
<input type="password" name="password" aria-label="password" autocomplete="off">
</div>
</div>
<div class="row">
<input type="submit" value="Submit">
</div>
{!! Form::close() !!}
这是创建和存储控制器
public function create()
{
return view('user_super_admin.create')
->with('divisions', $this->divisions);
}
/**
* Store a newly created User in storage.
*
* @param CreateUserRequest $request
*
* @return Response
*/
public function store(CreateUserRequest $request)
{
$input = $request->all();
$user = $this->userRepository->create($input);
Flash::success('User saved successfully.');
return redirect(route('users.index'));
}
CreateUserRequest
public function rules()
{
return User::$rules;
}
用户模型
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username',
'password',
'group_id',
'division_id',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'username' => 'string',
'password' => 'string',
'group_id' => 'integer',
'division_id' => 'integer',
'email_verified_at' => 'datetime',
];
public function group()
{
return $this->belongsTo("App\Models\Group");
}
public function division()
{
return $this->belongsTo("App\Models\Division");
}
}
用户存储库
/**
* @var array
*/
protected $fieldSearchable = [
'fullname',
'username',
'password',
'role_id',
'division_id',
'remember_token'
];
/**
* Configure the Model
**/
public function model()
{
return User::class;
}