Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Answer

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',
]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...