Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Correct image validate (laravel)

I have an image field that should not be required, but should be limited to possible file types
But, if I validate mimes, submitting the form without an image does not work

request()->validate([
       'name' => ['required'],'name' => ['required'],
       'type' => ['required'],'master_id' => ['required'],
       'description' => ['required'],
       'whom_id' => ['required'], 'short_description' => ['required'],
       'image' => ['mimes:jpg,bmp,png','max:3072'],
        ]);
if(request()->image){
        $ext = request()->file('image')->extension();//Получение расширения файла
        $path = request()->file('image')->storeAs('image', $course->id.'mainImage.'.$ext);
        $course->image = $path;
 }

validate err

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Normally for standard form submits, the answer is sometimes, however you’re submitting by Vue, so it required nullable.

    'image' => ['nullable', 'mimes:jpg,bmp,png','max:3072'],

Mind the Note On Optional Fields.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading