I want to display data from the controller
and throw it in the view as a dataset, but I have trouble how to write a loop on scriptjava
.
This is the code that I have tried, and still fails
This my 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'));
}
and this my view:
laravel
<script type="text/javascript">
var month= [
<?php foreach ($query as $bulan): ?>
<?php echo (string)$bulan ?>
<?php endforeach; ?>
];
</script>
I expected the result will be like this:
"var month= [1,2,3,4,5,6,7,8,9,10,11,12];"
So that it can be read on the dataset