我是laravel的初学者。
如果表单数据无效,我想重定向其他页面。
这是我的控制器代码:
public function register(Request $request) {
$this->validation($request);
User::create($request->all());
return $request->all();
}
public function validation($request) {
$validatedData = $request->validate([
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users,email',
'password' => 'required|min:6',
'confirm_password' =>'required|min:6|same:password',
]);
}
答案 0 :(得分:1)
您可以当一名选民
$validator = Validator::make($request->all() , [
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users,email',
'password' => 'required|min:6',
'confirm_password' =>'required|min:6|same:password',
])
然后检查它是否失败并执行重定向
if ($validator->fails()) {
return redirect('your/other/page/url')
->withErrors($validator)
->withInput();
}
更详细的描述可以在这里https://laravel.com/docs/5.7/validation#manually-creating-validators