Exemplo n.º 1
0
 /**
  * Deleta o usuario
  * $request e $response usam interface psr7
  * $args contém os argumentos informados na rota
  *
  * @param Slim\Http\Request $request
  * @param Slim\Http\Response $response
  * @param array $args
  * @return void|Slim\Http\Response
  */
 public function delete($request, $response, $args)
 {
     $id = $args['id'];
     $validations = [v::intVal()->validate($id)];
     if ($this->validate($validations) === false) {
         return $response->withStatus(400);
     } else {
         $usuario = Models\Usuario::with('relationDependentes')->find($id);
         if ($usuario) {
             $dependentes = $usuario->relationDependentes->all();
             if ($dependentes) {
                 $status = 403;
                 echo $this->error('delete#usuarios{id}', $request->getUri()->getPath(), $status, 'FK_CONSTRAINT_ABORT');
                 return $response->withStatus($status);
             } else {
                 $usuario->delete();
             }
         } else {
             $status = 404;
             echo $this->error('delete#usuarios{id}', $request->getUri()->getPath(), $status);
             return $response->withStatus($status);
         }
     }
 }