freemium's avatar

image validation error

I have an input type file here I can select multiple images i trying to add validation for the image and it throws the error even after uploading valid images


        if ($request->hasFile('images')) {
            $this->validate($request, [
                'images' => 'image|mimes:png,jpg,jpeg|max:2000'
            ]);
        }
        dd($request->all());

while dd($request->all()) before validation

array:12 [▼
  "_token" => "dPDIckl4rTKuY2R4JBXo29eoIn1ZM2Se78Cl3Fqz"
  "user_id" => "3"
  "store_id" => "1"
  "title" => "Hic quos eveniet ap"
  "price" => "124"
  "category_id" => "3"
  "rate" => "78"
  "starts_on" => "1903-01-02"
  "ends_on" => "1996-10-06"
  "tags" => array:1 [▶]
  "description" => "<p>Laudantium, nobis be.</p>"
  "images" => array:6 [▼
    0 => Illuminate\Http\UploadedFile {#2303 ▼
      -test: false
      -originalName: "153676225_3874021279326905_397701175869737197_o.jpg"
      -mimeType: "image/jpeg"
      -error: 0
      #hashName: null
      path: "C:\xampp\tmp"
      filename: "phpC08A.tmp"
      basename: "phpC08A.tmp"
      pathname: "C:\xampp\tmp\phpC08A.tmp"
      extension: "tmp"
      realPath: "C:\xampp\tmp\phpC08A.tmp"
      aTime: 2022-04-07 17:30:24
      mTime: 2022-04-07 17:30:24
      cTime: 2022-04-07 17:30:24
      inode: 2533274793710595
      size: 468412
      perms: 0100666
      owner: 0
      group: 0
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
      linkTarget: "C:\xampp\tmp\phpC08A.tmp"
    }
    1 => Illuminate\Http\UploadedFile {#2289 ▼
      -test: false
      -originalName: "153698751_3874021275993572_1070097753376424375_o.jpg"
      -mimeType: "image/jpeg"
      -error: 0
      #hashName: null
      path: "C:\xampp\tmp"
      filename: "phpC09B.tmp"
      basename: "phpC09B.tmp"
      pathname: "C:\xampp\tmp\phpC09B.tmp"
      extension: "tmp"
      realPath: "C:\xampp\tmp\phpC09B.tmp"
      aTime: 2022-04-07 17:30:24
      mTime: 2022-04-07 17:30:24
      cTime: 2022-04-07 17:30:24
      inode: 1688849863578639
      size: 814960
      perms: 0100666
      owner: 0
      group: 0
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
      linkTarget: "C:\xampp\tmp\phpC09B.tmp"
    }
    2 => Illuminate\Http\UploadedFile {#2293 ▼
      -test: false
      -originalName: "153722473_3874021352660231_2207958297101936109_o.jpg"
      -mimeType: "image/jpeg"
      -error: 0
      #hashName: null
      path: "C:\xampp\tmp"
      filename: "phpC09C.tmp"
      basename: "phpC09C.tmp"
      pathname: "C:\xampp\tmp\phpC09C.tmp"
      extension: "tmp"
      realPath: "C:\xampp\tmp\phpC09C.tmp"
      aTime: 2022-04-07 17:30:24
      mTime: 2022-04-07 17:30:24
      cTime: 2022-04-07 17:30:24
      inode: 562949956736016
      size: 624415
      perms: 0100666
      owner: 0
      group: 0
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
      linkTarget: "C:\xampp\tmp\phpC09C.tmp"
    }
    3 => Illuminate\Http\UploadedFile {#2314 ▼
      -test: false
      -originalName: "154385998_3874021299326903_5943666842858282776_o.jpg"
      -mimeType: "image/jpeg"
      -error: 0
      #hashName: null
      path: "C:\xampp\tmp"
      filename: "phpC0AC.tmp"
      basename: "phpC0AC.tmp"
      pathname: "C:\xampp\tmp\phpC0AC.tmp"
      extension: "tmp"
      realPath: "C:\xampp\tmp\phpC0AC.tmp"
      aTime: 2022-04-07 17:30:24
      mTime: 2022-04-07 17:30:24
      cTime: 2022-04-07 17:30:24
      inode: 562949956736017
      size: 722923
      perms: 0100666
      owner: 0
      group: 0
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
      linkTarget: "C:\xampp\tmp\phpC0AC.tmp"
    }
    4 => Illuminate\Http\UploadedFile {#2297 ▼
      -test: false
      -originalName: "154971861_3874021262660240_6140267197914958612_o.jpg"
      -mimeType: "image/jpeg"
      -error: 0
      #hashName: null
      path: "C:\xampp\tmp"
      filename: "phpC0AD.tmp"
      basename: "phpC0AD.tmp"
      pathname: "C:\xampp\tmp\phpC0AD.tmp"
      extension: "tmp"
      realPath: "C:\xampp\tmp\phpC0AD.tmp"
      aTime: 2022-04-07 17:30:24
      mTime: 2022-04-07 17:30:24
      cTime: 2022-04-07 17:30:24
      inode: 562949956736018
      size: 470572
      perms: 0100666
      owner: 0
      group: 0
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
      linkTarget: "C:\xampp\tmp\phpC0AD.tmp"
    }
    5 => Illuminate\Http\UploadedFile {#2322 ▼
      -test: false
      -originalName: "274247516_1564733457239216_8909139565486759863_n.jpg"
      -mimeType: "image/jpeg"
      -error: 0
      #hashName: null
      path: "C:\xampp\tmp"
      filename: "phpC0AE.tmp"
      basename: "phpC0AE.tmp"
      pathname: "C:\xampp\tmp\phpC0AE.tmp"
      extension: "tmp"
      realPath: "C:\xampp\tmp\phpC0AE.tmp"
      aTime: 2022-04-07 17:30:24
      mTime: 2022-04-07 17:30:24
      cTime: 2022-04-07 17:30:24
      inode: 562949956736019
      size: 502015
      perms: 0100666
      owner: 0
      group: 0
      type: "file"
      writable: true
      readable: true
      executable: false
      file: true
      dir: false
      link: false
      linkTarget: "C:\xampp\tmp\phpC0AE.tmp"
    }
  ]
]

my form

<form action="{{ route('my-product.store') }}" method="POST" enctype="multipart/form-data" id="formId">
        @csrf
        <button  formenctype="multipart/form-data" type="submit">Add</button>
        <button type="submit" id="buttonId1"  formaction="{{ route('my-product.draft') }}"
            formenctype="multipart/form-data">{{ trans('product::form.saveAsDraftBtnText') }}</button>
</form>
error shown  in blade file

The images must be an image. The images must be a file of type: png, jpg, jpeg.


please help me here to resolve my problem
0 likes
1 reply
MichalOravec's avatar
Level 75
$this->validate($request, [
    'images' => 'array',
    'images.*' => 'image|mimes:png,jpg,jpeg|max:2000'
]);

if ($request->hasFile('images')) {
    //
}

Please or to participate in this conversation.