Level 1
Hi
-
It’s non-standard to use PUT/PATCH for creating resources: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT
-
What’s the request and how is it different between POST (apparently working) and PUT (apparently not)?
when i use put/patch where mediatype="application/json" it works finely but i need to upload file too. how can i fix this ?
/**
* create testimonial
* @OA\put(
* path="/api/testimonial/store",
* tags={"testimonial"},
* security={{"apiAuth":{}}},
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(property="name",type="string"),
* @OA\Property(property="description",type="string"),
* @OA\Property(property="designation",type="string"),
* @OA\Property(property="company",type="string"),
* @OA\Property(property="image",type="file",format="string"),
* )
* )
* ),
* @OA\Response(
* response="200",
* description="successful operation",
* ),
* @OA\Response(
* response=400,
* description="invalid",
* @OA\JsonContent(
* @OA\Property(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());
}
}
Please or to participate in this conversation.