Last active
February 4, 2019 06:22
-
-
Save yasaryousuf/3438916340c3accf64f314ed1906916b to your computer and use it in GitHub Desktop.
multiple file upload validation with array in laravel 5.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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