When i try to validate a image file after submitting the form via jquery
$('#logo').submit();
am always getting the validation error as
The img field is required
Here is the validation that i used for validating the file
$input = array('img' => Input::file('img'));
$rules = array(
'img' => 'required',
);
// Now pass the input and rules into the validator
$validator = Validator::make($input, $rules);
// check if the validator failed -----------------------
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
print_r($messages);
}
I failed to identify what is the problem with the script, Help me to overcome the issue. Thanks in advance.
To submit files with jQuery + ajax to Laravel, I follow this approach:
An example form:
An example ajax request:
And in the backend (Laravel):