when i use put/patch in mediatype=”application/json” it works finely but i need to upload file too. how can i fix this ?
/**
* create testimonial
* @OAput(
* path="/api/testimonial/store",
* tags={"testimonial"},
* security={{"apiAuth":{}}},
* @OARequestBody(
* required=true,
* @OAMediaType(
* mediaType="multipart/form-data",
* @OASchema(
* @OAProperty(property="name",type="string"),
* @OAProperty(property="description",type="string"),
* @OAProperty(property="designation",type="string"),
* @OAProperty(property="company",type="string"),
* @OAProperty(property="image",type="file",format="string"),
* )
* )
* ),
* @OAResponse(
* response="200",
* description="successful operation",
* ),
* @OAResponse(
* response=400,
* description="invalid",
* @OAJsonContent(
* @OAProperty(property="msg", type="string", example="fail"),
* )
* )
* )
* */
public function store(Request $request)
{
try {
$testimonial = new Testimonial;
$testimonial->name = $request->name;
$testimonial->description = $request->description;
$testimonial->designation = $request->designation;
$testimonial->company = $request->company;
if ($request->hasfile('image')) {
$file = $request->file('image');
$extenstion = $file->getClientOriginalExtension();
$filename = time() . '.' . $extenstion;
$file->move('uploads/testimonial/', $filename);
$testimonial->image = $filename;
}
$testimonial->save();
return $this->returnJson($testimonial, 'Testimonials successfully created!', 200, ['total' => $testimonial->count()]);
} catch (Exception $e) {
return $this->returnJson(false, $e->getMessage(), $e->getCode());
}
}