34 lines
893 B
PHP
34 lines
893 B
PHP
<?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()]);
|
|
}
|
|
}
|
|
}
|