I want to show the custom validation error message if user upload an image size of more than 4 MB. However, once submitted with an image of like above 4MB, it shows the default error message : "The file name failed to upload.". Below is my code in the controller:
$messages = [
'fileName' => 'Image maximum size exceed. ',
];
$validator = Validator::make($request->all(), [
'fileName' => 'max:4096',
], $messages);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator->errors());
}
Here is the HTML code in the blade file:
<input type="file" name="fileName">
fileName.maxin your$messagesarray