我正在尝试验证发帖请求。我认为验证失败时,会显示此错误消息。
app / Http / Controllers / InternationalShippingController.php
public function store(Request $request){
//echo '<pre>';
$post = $request->post();
$order_ids = session('international_order_ids');
//var_dump($order_ids);
//var_dump($post);
$validator = Validator::make(
$post,[
'documents.*' => 'mimes:jpg,jpeg,png,pdf|max:5000|nullable',
'company_name' => 'nullable',
'shipping_address1' => 'nullable',
'message' => 'size:1000',
],[
'image_file.*.mimes' => __('Only jpeg,png and pdf files are allowed'),
'image_file.*.max' => __('Sorry! Maximum allowed size for an document is 5MB'),
]
);
if($validator->fails()){
return redirect('internationalshippings/create2')
->withErrors($validator)
->withInput();
}
}
web.php
Route::post('internationalshippings/create2','InternationalShippingController@create2');
Route::resource('internationalshippings','InternationalShippingController');
我还没有在控制器中使用show()方法。此错误是否表示验证失败时会尝试重定向到internationalshippings / show方法?验证失败后,我想将其重定向回internationalshippings / create2。我该如何实现?
谢谢
您正在使用resource
控制器,在resources
中,此网址internationalshippings/SomeThing
表示show
方法,因此您可以在失败返回中使用它:return redirect()->route('your_route_name')
或return back()
第二种方法在您的web.php中,当您定义资源路由时,请按以下方式键入:Route::resource('internationalshippings','InternationalShippingController',['except'=>['show']]);