gpt4 book ai didi

javascript - Laravel-5.7 : How to view data in dataset chart in Laravel

转载 作者:搜寻专家 更新时间:2023-10-31 08:49:49 24 4
gpt4 key购买 nike

我想显示来自 controller 的数据并将其作为数据集放入 View 中,但我无法在 scriptjava 上编写循环。

这是我试过的代码,但仍然失败

这是我的 Controller :

laravel
$query = DB::table('app_history_calls')
->SELECT(DB::raw("(MONTH(date)) as bulan"))
->GROUPBY('date',DB::raw("MONTH(date)"))
->ORDERBY('date','asc')->get();


return view('dashboard.index',compact('query'));
}

这是我的观点:

laravel
<script type="text/javascript">

var month= [
<?php foreach ($query as $bulan): ?>

<?php echo (string)$bulan ?>

<?php endforeach; ?>
];
</script>

我预计结果会是这样的:

"var month= [1,2,3,4,5,6,7,8,9,10,11,12];"

这样就可以在dataset上读取了

最佳答案

  $data['query'] =  DB::table('app_history_calls')
->SELECT(DB::raw("(MONTH(date)) as bulan"))
->GROUPBY('date',DB::raw("MONTH(date)"))
->ORDERBY('date','asc')->get();


return view('dashboard.index')->withdata($data);
}
 <script type="text/javascript">

var month= [
<?php foreach ($data['query'] as $bulan): ?>

<?php echo (string)$bulan ?>

<?php endforeach; ?>
];
</script>

用你的代码替换上面的代码我在 $data 数组中传递值并在 for 循环中读取 js 中的 $data['query']

关于javascript - Laravel-5.7 : How to view data in dataset chart in Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56301594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com