I need to validate multiple uploaded files, making sure they are of a specific type and under 2048kb. The below doesn\'t appear to check all files in the array \'files\' an
Please try this:
public function fileUpload(Request $request) {
$rules = [];
$files = count($this->input('files')) - 1;
foreach(range(0, $files) as $index) {
$rules['files.' . $index] = 'required|mimes:png,jpeg,jpg,gif|max:2048';
}
$validator = Validator::make($request->all() , $rules);
if ($validator->fails()) {
return response()->json(array(
'success' => false,
'errors' => $validator->getMessageBag()->toArray()
) , 400);
}
}