Laravel API 프로젝트 16단계 - 유저 삭제 API

Route::delete('/users/{id}', [UserController::class, 'deleteUser']);

 

routes/api.php 파일에 위의 코드를 추가해줍니다.

 

    public function deleteUser(int $id): Response
    {
        User::destroy($id);

        return response()->noContent(Response::HTTP_NO_CONTENT);
    }

 

laravel-api/app/Http/Controllers/UserController.php 파일에 deleteUser 메서드를 추가해줍니다.

id에 해당하는 유저를 삭제합니다.

 

root@webgori-1:~# curl --location --request DELETE 'http://localhost/api/users/21'