我有注册新用户的验证,但每次我提交它只是重新加载并停留在页面中,我迷路了,但是当我使用Registration :: create($ request-> all())而没有验证它从顶部推进并保存数据。请帮忙
我的控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Registration;
class RegistrationsController extends Controller
{
public function index(){
return view('registrations.create');
}
public function store(){
request()->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
$validatedUser = Registration::create([
'name' => request('name'),
'email' => request('email'),
'password' => bcrypt(request('password'))
]);
return redirect()->home();
}
}
这是我的create.blade
<form action="{{ route('registrations.store') }}" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="">Full Name</label>
<input type="text" class="form-control" name="name" id="name" aria-describedby="helpId" placeholder="Juan Dela Cruz">
<small id="helpId" class="form-text text-muted">Ex. Juan Dela Cruz</small>
</div>
<div class="form-group">
<label for="">Password</label>
<input type="password" class="form-control" name="password" id="password" placeholder="type password here..">
</div>
<div class="form-group">
<label for="">Confirm password</label>
<input type="password" class="form-control" name="password_confirm" id="password_confirm" placeholder="type password here..">
</div>
<div class="form-group">
<label for="">Email address</label>
<input type="email" class="form-control" name="email" id="email" aria-describedby="emailHelpId" placeholder="juandelacruz@gmail.com">
<small id="emailHelpId" class="form-text text-muted">Must be valid email address</small>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
对于我刚刚使用Route :: resource
的路线谢谢
答案 0 :(得分:2)
这可能是因为您的密码确认失败了。
您的确认字段必须命名为:password_confirmation
而不是password_confirm
,如文档所示:
验证字段必须具有foo_confirmation的匹配字段。例如,如果验证字段为password,则输入中必须存在匹配的password_confirmation字段。