How can show jason to html?

i need show the message of notification like html but it's not working, i have this code
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
TextEntry::make('id'),
TextEntry::make('type'),
TextEntry::make('data')
->label('Detalles')
->formatStateUsing(function ($state) {
$decodedData = json_decode($state, true);

if (json_last_error() !== JSON_ERROR_NONE) {
return 'Error al decodificar los datos.';
}

// Construir un texto legible para la columna
$body = $decodedData['body'] ?? 'Sin descripción.';
$actions = $decodedData['actions'] ?? [];
$formattedActions = '';

foreach ($actions as $action) {
$formattedActions .= "- {$action['label']} ({$action['url']})\n";
}

return "Descripción: {$body}\nAcciones:\n{$formattedActions}";
}),
]);
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
TextEntry::make('id'),
TextEntry::make('type'),
TextEntry::make('data')
->label('Detalles')
->formatStateUsing(function ($state) {
$decodedData = json_decode($state, true);

if (json_last_error() !== JSON_ERROR_NONE) {
return 'Error al decodificar los datos.';
}

// Construir un texto legible para la columna
$body = $decodedData['body'] ?? 'Sin descripción.';
$actions = $decodedData['actions'] ?? [];
$formattedActions = '';

foreach ($actions as $action) {
$formattedActions .= "- {$action['label']} ({$action['url']})\n";
}

return "Descripción: {$body}\nAcciones:\n{$formattedActions}";
}),
]);
}
i try with
->html()
->html()
but not working Any recommendation or idea for fix this problem?
No description
2 Replies
TranceCode
TranceCodeOP2w ago
Well, i fix my problem using this code!
TextEntry::make('data')
->label('Detalles')
->formatStateUsing(function ($state) {
// Decodificamos el JSON, data de la tabla
$data = json_decode($state, true);
if (!$data) {
return 'Formato inválido';
}
//Construimos de json al HTML
$html = '<div>';
$html .= "<h4>{$data['title']}</h4>";
$html .= "<p>{$data['body']}</p>";
if (isset($data['actions']) && is_array($data['actions'])) {
$html .= '<ul>';
foreach ($data['actions'] as $action) {
$html .= "<li><a href='{$action['url']}' target='_blank' class='text-blue-500 hover:text-blue-700 font-semibold'>{$action['label']}</a></li>";
}
$html .= '</ul>';
}
$html .= '</div>';
return $html;
})
->html()
TextEntry::make('data')
->label('Detalles')
->formatStateUsing(function ($state) {
// Decodificamos el JSON, data de la tabla
$data = json_decode($state, true);
if (!$data) {
return 'Formato inválido';
}
//Construimos de json al HTML
$html = '<div>';
$html .= "<h4>{$data['title']}</h4>";
$html .= "<p>{$data['body']}</p>";
if (isset($data['actions']) && is_array($data['actions'])) {
$html .= '<ul>';
foreach ($data['actions'] as $action) {
$html .= "<li><a href='{$action['url']}' target='_blank' class='text-blue-500 hover:text-blue-700 font-semibold'>{$action['label']}</a></li>";
}
$html .= '</ul>';
}
$html .= '</div>';
return $html;
})
->html()
Want results from more Discord servers?
Add your server