安装adminlte后如何解决用户名问题
How to solve username issue after installing adminlte
我安装了一个jeroennoten/Laravel-AdminLTE
即,包版本 2.x (Laravel 6)。安装后,我修改我的用户 table、register.blade.php 并为用户名和角色注册控制器。但是当我提交表单时,它总是给我一个错误,默认值未设置为用户名。
这是我的观点
<div class="form-group has-feedback {{ $errors->has('role') ? 'has-error' : '' }}">
<select name="role" class="form-control">
<option>Register As</option>
<option value="candidate">Candidate</option>
<option value="voter">Voter</option>
</select>
<span class="glyphicon glyphicon-role form-control-feedback"></span>
@if ($errors->has('role'))
<span class="help-block">
<strong>{{ $errors->first('role') }}</strong>
</span>
@endif
</div>
<div class="form-group has-feedback {{ $errors->has('username') ? 'has-error' : '' }}">
<input type="text" name="username" class="form-control" value="{{ old('username') }}"
>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
还有我的注册控制器
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'username' => ['required', 'string'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:6', 'confirmed'],
'role' => ['required'],
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'username' => $data['username'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'role' => $data['role'],
]);
}
提交修改后总是出现这个错误
SQLSTATE[HY000]: General error: 1364 Field 'username' doesn't have a
default value (SQL: insert into users
(name
, email
, password
,
updated_at
, created_at
) values (Tanvir, tahmedhera@gmail.com,
yXxgDoe272G0wkrcpQYmLepTCGPTPzASBkzXxJ84EhZqOEBvy4zFS,
2019-10-25 10:54:25, 2019-10-25 10:54:25)) Please can somebody help
me why i getting this error
检查你的模型,我认为缺少用户名参数。
protected $fillable = [
'name', 'email', 'password', 'username', 'role'
];
在您的模型 User.php
中,您需要在 $fillable
中添加 username
您的模型 User.php
应该是这样的:
protected $fillable = [
'name', 'email', 'password', 'role', 'username
];
谢谢。
我安装了一个jeroennoten/Laravel-AdminLTE 即,包版本 2.x (Laravel 6)。安装后,我修改我的用户 table、register.blade.php 并为用户名和角色注册控制器。但是当我提交表单时,它总是给我一个错误,默认值未设置为用户名。 这是我的观点
<div class="form-group has-feedback {{ $errors->has('role') ? 'has-error' : '' }}">
<select name="role" class="form-control">
<option>Register As</option>
<option value="candidate">Candidate</option>
<option value="voter">Voter</option>
</select>
<span class="glyphicon glyphicon-role form-control-feedback"></span>
@if ($errors->has('role'))
<span class="help-block">
<strong>{{ $errors->first('role') }}</strong>
</span>
@endif
</div>
<div class="form-group has-feedback {{ $errors->has('username') ? 'has-error' : '' }}">
<input type="text" name="username" class="form-control" value="{{ old('username') }}"
>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
还有我的注册控制器
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'username' => ['required', 'string'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:6', 'confirmed'],
'role' => ['required'],
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'username' => $data['username'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'role' => $data['role'],
]);
}
提交修改后总是出现这个错误
SQLSTATE[HY000]: General error: 1364 Field 'username' doesn't have a default value (SQL: insert into
users
(name
,password
,updated_at
,created_at
) values (Tanvir, tahmedhera@gmail.com, yXxgDoe272G0wkrcpQYmLepTCGPTPzASBkzXxJ84EhZqOEBvy4zFS, 2019-10-25 10:54:25, 2019-10-25 10:54:25)) Please can somebody help me why i getting this error
检查你的模型,我认为缺少用户名参数。
protected $fillable = [
'name', 'email', 'password', 'username', 'role'
];
在您的模型 User.php
中,您需要在 $fillable
username
您的模型 User.php
应该是这样的:
protected $fillable = [
'name', 'email', 'password', 'role', 'username
];
谢谢。