<a href="./remover-img?id=<?= $video->id; ?>">Excluir Imagem</a>
'GET|/remover-img' => DeleteImageVideoController::class
public function removeImg(int $id): bool
{
$sql = "UPDATE videos SET image_path = NULL WHERE id = ?;";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(1, $id);
return $stmt->execute();
}
- em DeleteImageVideoController:
class DeleteImageVideoController implements Controller
{
public function __construct(private VideoRepository $videoRepository)
{
}
public function processaRequisicao(): void
{
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if ($id === null || $id === false) {
header('Location: /?sucesso=0');
return;
}
$success = $this->videoRepository->removeImg($id);
if ($success === false) {
header('Location: /?sucesso=0');
} else {
header('Location: /?sucesso=1');
}
}
}