30 lines
763 B
PHP
30 lines
763 B
PHP
<?php
|
|
|
|
namespace App\AI\Tools;
|
|
|
|
use App\Models\Noticia;
|
|
|
|
class EliminarNoticiaTool
|
|
{
|
|
public function __invoke(int $id_noticia): string
|
|
{
|
|
try {
|
|
$noticia = Noticia::find($id_noticia);
|
|
|
|
if (!$noticia) {
|
|
return json_encode(['error' => "No se encontró la noticia con ID: {$id_noticia}"]);
|
|
}
|
|
|
|
$titulo = $noticia->titulo;
|
|
$noticia->delete();
|
|
|
|
return json_encode([
|
|
'success' => true,
|
|
'mensaje' => "Noticia \"{$titulo}\" (ID {$id_noticia}) eliminada correctamente.",
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
return json_encode(['error' => 'No se pudo eliminar la noticia: ' . $e->getMessage()]);
|
|
}
|
|
}
|
|
}
|