Skip to content

Instantly share code, notes, and snippets.

@yasaryousuf
Last active February 4, 2019 06:22
Show Gist options
  • Save yasaryousuf/3438916340c3accf64f314ed1906916b to your computer and use it in GitHub Desktop.
Save yasaryousuf/3438916340c3accf64f314ed1906916b to your computer and use it in GitHub Desktop.
multiple file upload validation with array in laravel 5.x
<?php
public function store(Request $request)
{
$this->validate($request, [
'images.*' => 'required|mimes:jpg,jpeg,png,bmp|max:2000'
],[
'images.*.required' => 'Please upload an image only',
'images.*.mimes' => 'Only jpeg, png, jpg and bmp images are allowed',
'images.*.max' => 'Sorry! Maximum allowed size for an image is 2MB',
]);
// Write your code
}
######################## -- OR -- ##########################
public function store(Request $request)
{
$input = $request->all();
$validator = Validator::make(
$input,
[
'images.*' => 'required|mimes:jpg,jpeg,png,bmp|max:20000'
],[
'images.*.required' => 'Please upload an image',
'images.*.mimes' => 'Only jpeg,png and bmp images are allowed',
'images.*.max' => 'Sorry! Maximum allowed size for an image is 20MB',
]
);
if ($validator->fails()) {
// If fails then return Validation error..
}
// Write your code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment