我正在学习laravel,但我仍处于初学者水平。我使用php artisan make:auth
来创建身份验证代码。
我尝试在注册时添加额外的地址字段。但是在输入详细信息时,它仍然显示地址字段为空。
我想要有关如何消除错误的建议
感谢您的支持
RegisterController.php
我还在RegisterController.php中添加了地址字段
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'address' => ['required', 'text', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'username' => ['required', 'string', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:6', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'address' => $data['address'],
'email' => $data['email'],
'username' => $data['username'],
'password' => Hash::make($data['password']),
]);
}
register.blade.php
我还在register.blade.php中添加了地址字段
<div class="form-group row">
<label for="address" class="col-md-4 col-form-label text-md-right">{{ __('address') }}</label>
<div class="col-md-6">
<input id="address" type="text" class="form-control{{ $errors->has('address') ? ' is-invalid' : '' }}" address="address" value="{{ old('address') }}" required autofocus>
@if ($errors->has('address'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('address') }}</strong>
</span>
@endif
</div>
</div>
User.php:
我还在User.php中添加了地址字段
protected $fillable = [
'name', 'email','username','address', 'password',
];
答案 0 :(得分:3)
您的输入字段没有name
属性。必须将其转发到您的帖子数据中。
似乎您已将name
属性命名为address
。
答案 1 :(得分:0)
如Repox所说,更改您的这一行
<input id="address" type="text" class="form-control{{ $errors->has('address') ? ' is-invalid' : '' }}" address="address" value="{{ old('address') }}" required autofocus>
对此
<input id="address" name="address" type="text" class="form-control{{ $errors->has('address') ? ' is-invalid' : '' }}" address="address" value="{{ old('address') }}" required autofocus>