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>
Here is what you should do. Do not usecompact
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:
if(Auth::user()->hasRole('Super Admin')) {
$view_data['user'] = User::where('id', Auth::user()->id)->first();
$view_data['jumlah_user'] = User::orderBy('id', 'ASC')->get()->count();
$view_data['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');
});
$view_data['months']=[];
$view_data['monthCount']=[];
foreach($view_data['data'] as $month => $values){
$view_data['months'][]=$month;
$view_data['monthCount'][]=count($values);
}
return view('dashboard.admins', $view_data);
}
Now in your view file. You can just reference to each variable as you wish like this:{{ $user }}
{{ $months }}
{{ $jumlah_user }}
etcetera
You 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
return view('dashboard.admins', compact('user','jumlah_user','data','months','monthCount' ));
Method 2 => You can pass a single variable as array of different variables like
$view_data['user'][]=$user;
$view_data['jumlah_user'][]=$jumlah_user;
$view_data['months'][]=$month;
$view_data['data'][]=$data;
return view('dashboard.admins', compact('view_data'));
And use as normal on front end by accessing variable name
{{ $user }} {{ $months }} {{ $jumlah_user }}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.