Laravel 错误中的 HighCharts
HighCharts in Laravel Errors
大家好,我的 laravel 项目现在遇到了这个问题,我正在尝试从 highcharts 添加饼图,我在 home.blade.
中添加了 javascrips但是我遇到了这个问题,我需要解决,看看这个。
错误:
json_decode(): Argument #1 ($json) must be of type string, array given
代码:
控制器:
$decisiones = Visita::all();
$puntos = [];
foreach($decisiones as $decision )
{
$puntos = ['name' => $decision['registrante'], 'y' => $decision['id']];
}
return view('Reportes.ReporteTomaDecision', ["data" => json_decode($puntos)]);
视图
data: <?= $data ?>
这是我来自控制器的变量
看起来更像是您必须在视图中 return json 因此您必须对数据进行编码。
然后试试这个:
$decisiones = Visita::all();
$puntos = [];
foreach ($decisiones as $decision) {
$puntos = ['name' => $decision['registrante'], 'y' => $decision['id']];
}
return view('Reportes.ReporteTomaDecision', ["data" => json_encode($puntos)]);
查看:
<?= $data ?>
$decisiones = Visita::all();
$puntos = [];
foreach($decisiones as $decision )
{
$puntos[] = ['name' => $decision['registrante'], 'y' => $decision['id']];
}
$data = json_encode($puntos);
return view('Reportes.ReporteTomaDecision', compact($data)]);
go to ReporteTomaDecision blade
{{$data}}