please help me
I made a chart, but there is a problem when I want to display the data, why is it compacted?
example code controller :
if(Auth::user()->hasRole('Super Admin')) {
$user = User::where('id', Auth::user()->id)->first();
$jumlah_user = User::orderBy('id', 'ASC')->get()->count();
$data = Verifikasi_tte::join('surat_ttes', 'surat_ttes.id', '=', 'verifikasi_ttes.surat_tte_id')
->join('users', 'users.id', '=', 'surat_ttes.user_id')
->join('jenis_surat_ttes', 'jenis_surat_ttes.id', '=', 'surat_ttes.jenis_surat_tte_id')
->select('surat_ttes.id','surat_ttes.klasifikasi','surat_ttes.no_surat','surat_ttes.tgl_surat','surat_ttes.created_at',
'jenis_surat_ttes.nama_jenis_surat','users.name','users.opd_id','verifikasi_ttes.status')
->get()->groupBy(function($data){
return Carbon::parse($data->created_at)->format('M');
});
$months=[];
$monthCount=[];
foreach($data as $month => $values){
$months[]=$month;
$monthCount[]=count($values);
}
return view('dashboard.admins', compact('user','jumlah_user', ['data'=>$data,'months'=>$months,'monthCount'=>$monthCount] ));
}
if there is a data dump in the dump, it’s strange why the compact section asks for the sep variable?
example js chart :
<script type="text/javascript">
var _ydata=JSON.parse('{!! json_encode($months) !!}');
var _xdata=JSON.parse('{!! json_encode($monthCount) !!}');
</script>
2
Answers
Here is what you should do. Do not use
compact
as it cannot have an array as an argument. Instead you should pass all your data as an array which is broken down into the various variables when accessing it in your view file.Adjust your code to this:
Now in your view file. You can just reference to each variable as you wish like this:
{{ $user }}
{{ $months }}
{{ $jumlah_user }}
etceteraYou can not pass single varibles with array of variables inside compact method. You can do two step here for passing each varible to view.
Method 1 => you can pass each variable as comma separated list inside compact and get in front end by variable name
Method 2 => You can pass a single variable as array of different variables like
And use as normal on front end by accessing variable name