<img height="1" width="1" style="display:none;" alt="" src="https://ct.pinterest.com/v3/?event=init&amp;tid=2612994575055&amp;pd[em]=<hashed_email_address>&amp;noscript=1">
Skip to content
    AdminOct 2, 2023 6:57:12 PM1 min read

    Swagger Post Method in Laravel

    In previous two articles we Create Laravel Swagger API and Create Swagger Configuration in Laravel. Now we will add Swagger Post Method in Laravel.

    
         /**
         * @OA\Post(
         *      path="/update-user/{id}",
         *      operationId="updatePassword",
         *      tags={"User"},
         *      summary="Update Password",
         *      description="Update Password",
         *      @OA\RequestBody(
         *      required=true,
         *      description="Update Password parameters",
         *		@OA\Parameter(
         *      name="id",
         *      in="path",
         *      required=true,
         *      description= "user id",
         *      example="10",
         *      @OA\Schema(
         *           type="integer"
         *      )
         *      ),
         *      @OA\MediaType(
         *            mediaType="multipart/form-data",
         *            @OA\Schema(
         *               type="object",
         *       @OA\Property(property="full_name", type="string", format="string", example="Chetan", description ="Your full name"),
         *       @OA\Property(property="last_name", type="string", format="string")
         *            )
         *        ),
         *      ),
         *       @OA\Response(
         *      response=200,
         *      description="Success response",
         *      @OA\JsonContent(
         *      @OA\Property(property="status", type="number", example="200"),
         *      @OA\Property(property="message", type="string", example="User updated successfully."),
         *        )
         *     ),
         *        @OA\Response(
         *      response=400,
         *      description="Bad Request",
         *      @OA\JsonContent(
         *      @OA\Property(property="status", type="number", example="400"),
         *      @OA\Property(property="message", type="string", example="Error in processing request")
         *        )
         *     )
         * )
         *      
         * )
         */
    
        public function updateUser($id,Request $request)
        {
        	try {
    	    	$user = User::where('id', $id)->update(['full_name' => $request->input('full_name')]);
    
    	    	if($user){
    	    		return response()->json(['status' => 200, 'message' => 'User updated successfully'], 200);
    	    	}
        	}catch (\Exception $e) {
                return response()->json(['status' => 400, 'message' => 'Error in processing request'], 400);
            }
        }

    Now, run php artisan l5-swagger:generate and check api at https://mywebsite.com/api/documentation.

    Check Laravel swagger GET Method.

    Read laravel swagger documentation here.

    COMMENTS

    RELATED ARTICLES