Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

multiple image validation in laravel

I am applying laravel validation for multiple image it works for single iamge upload but can not works for multiple what is mistake done by me?

$this->validate($request, array(
     'imagenew.*' => 'required|mimetypes:image/jpeg,image/png,image/jpg',
     'image'=>'required|mimes:jpeg,png,jpg',
        
));

Blade :

<div class="col-sm-4">
    <label for="image" class=" form-control-label">Property Single Image</label>
    <input type="file" id="image" name="image" class="form-control-file">
   <span class="text-danger" required>{{ $errors->first('image') }}</span>
    
</div>
<div class="col-sm-4">
    <label for="imagenew" class=" form-control-label">Property Multiple Image</label>
    <input type="file" id="imagenew" name="imagenew[]" class="form-control-file" multiple>
  <span class="text-danger" required>{{ $errors->first('imagenew') }}</span>
</div>
question from:https://stackoverflow.com/questions/66058214/multiple-image-validation-in-laravel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this :

$validated = $request->validate([
   'imagenew' => 'required|array',
   'imagenew.*' => 'required|mimes:jpeg,png,jpg',
   'image'=>'required|mimes:jpeg,png,jpg',
]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...