Issue
I'm trying to validate post request. I think when the validation fails, it gives me this error message.
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');
I haven't made show() method in the controller. Does this error mean when the validation fails, it tries to redirect to internationalshippings/show method? When the validation fails,I'd like this to redirect back to internationalshippings/create2. How can I achieve this?
Thank you
Solution
you are using the resource
controller,
in resources
this url internationalshippings/SomeThing
means the show
method i mean this url calls the show
method in resource
First way
so you can use this in your fail return:
return redirect()->route('your_route_name')
OR return back()
Second way
and the second way is in your web.php, when you are defining the resource route, type in this way:
Route::resource('internationalshippings','InternationalShippingController',['except'=>['show']]);
EDIT:
in your code situation the best way is change Return
, because the url that you want to redirect to it, is POST
Answered By - Reza sh
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.