我的问题是,我的表单验证失败,但方法$this->validate($request, $rules, $messages)
不会重定向-> back()
,而是重定向到根页面/
。流明 - 验证方法重定向到网站的根目录
验证失败时,是否有可能改变重定向?
我的问题是,我的表单验证失败,但方法$this->validate($request, $rules, $messages)
不会重定向-> back()
,而是重定向到根页面/
。流明 - 验证方法重定向到网站的根目录
验证失败时,是否有可能改变重定向?
我昨天碰到了同样的问题,解决的办法是让自己的验证实例:
#be sure to include the Validator class
use Validator;
#in your function (if input is coming from a form)
v = Validator::make($request->all(), ['fieldname1', 'fieldname2']);
if ($v->fails()) {
#return json error
return response()->json(['success' => false, 'errors' => $v->errors()]);
#other return could be
#return view('page/name', 'errors' => $v->errors());
}
// process code here since we've passed validation
在trait ValidatesRequests
有一个buildFailedValidationResponse
功能,在验证失败时它不是一个Ajax请求被重定向(和或json请求)
在它调用$this->getRedirectUrl()
的方法中,因此请确保此功能访问的任何属性都已正确设置