Ahora si(?
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?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()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user