How to make a delete in SLIM that is a PHP framework?

0

I want to delete by id and the backend statements in slim v3, I do not know how it is done ... I have the following sentences for example a get that I do I do it in the following way:

Thanks in advance!

                    $app->get('/obtenerUsuarios', function (Request $request, Response $response, $args) {
                        // Para devolverlos todos los usuarios
                        $Usuarios = Usuarios::get();

                        // mas recomendado usar esta forma
                        return sendOkResponse($Usuarios ->toJson(),$response);
                    });


                    // Imprimir en formato JSON
                    function sendOkResponse($message,$response){
                        $newResponse = $response->withStatus(200)->withHeader('Content-Type','application/json');
                        $newResponse ->getBody()->write($message);
                        return $newResponse;
                    }

This is how I have to eliminate by the id of the user but I do not know what statements you have to put in without using bd, the pdo or those things that I do not know if the truth can be ...

                $app->delete('/borrarUsuario/{id}', function ($request, $response, $args) {
                    // Delete book identified by $args['id']


                });
    
asked by Daniel 18.03.2018 в 01:17
source

1 answer

0
$app->delete('/borrarUsuario/{id}', function ($request, $response, $args) {

  $id = $request->getAttribute('id');

  $usuario = Usuarios::find($id);

  $usuario->delete();
});
    
answered by 21.03.2018 в 00:49