Laravel 5.5,验证后无法通过数据
Laravel 5.5, cant pass data after validation
我有这个注册新用户的验证,但每次我提交它只是重新加载并停留在页面中,我迷路了,但是当我使用 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
谢谢
这可能是因为您的密码确认失败。
您的确认字段必须命名为:password_confirmation
而不是文档中所说的 password_confirm
:
The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.
我有这个注册新用户的验证,但每次我提交它只是重新加载并停留在页面中,我迷路了,但是当我使用 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
谢谢
这可能是因为您的密码确认失败。
您的确认字段必须命名为:password_confirmation
而不是文档中所说的 password_confirm
:
The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.