1

I am confused about the behaviour of postman. I don't know what is the problem. I am working on an API. When I send the data through form-data it throws me an error saying these fields are required. But when I pass same data through x-www urlencoded it works fine. But as I could not be able to upload image so I want to solve the problem of form-data.

Here is the picture for form-data's output and urlencoded output.

enter image description here

And for urlencoded

enter image description here

Here us Users Conntroller code:

 $data = $request->validate([
    'dob' => 'required',
    'gender'=>'required|in:male,female',
    'image'=>'required|mimes:jpg,png,jped|max:5048'
]);
$newImage = time().'-'.$request->name.'.'.$request->image->extension();
$request->image->move(public_path('images'), $newImage);
$user = User::find($id);
$user ->dob = $request->dob;
$user ->gender = $request->gender;
$user ->image= $newImage;
$user ->save();
return response($user);
Hassan Ali
  • 35
  • 7

0 Answers0