Ahora si :)))))))))))))))))
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\AI\Tools;
|
||||
|
||||
use App\Models\Noticia;
|
||||
|
||||
class RedactarNoticiaTool
|
||||
{
|
||||
public function __invoke(
|
||||
string $titulo,
|
||||
string $contenido,
|
||||
?int $id_torneo = null,
|
||||
?string $categoria = null
|
||||
): string {
|
||||
try {
|
||||
$noticia = Noticia::create([
|
||||
'titulo' => $titulo,
|
||||
'contenido' => $contenido,
|
||||
'fecha' => now(),
|
||||
'id_torneo' => $id_torneo,
|
||||
'categoria' => $categoria,
|
||||
]);
|
||||
|
||||
return json_encode([
|
||||
'success' => true,
|
||||
'id_noticia' => $noticia->id,
|
||||
'mensaje' => "Noticia \"{$titulo}\" creada correctamente.",
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return json_encode(['error' => 'No se pudo crear la noticia: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user