I have tried everything to get the data total of Jumlah Hadir, Jumlah Sakit, and Jumlah Izin there for every user. as a beginner I am very confused. For a clear view I want, you can see the image below:
this is a piece of my queries in controller, so many query from anywhere I try to get the data total, and this is one of many:
$data = Absence::with('teacher','data_mapel','data_kelas','data_siswa','data_tahun_ajaran','data_unit') ->select('*', DB::raw('(SELECT COUNT(*) FROM absensi_siswa WHERE absensi = "Hadir") as jumlah_hadir'));
with the query above. I get the result like the table above.
I want the data unique based on Nama Lengkap field and I wish the data total show up on my table for every user.
what queries should I write on to get the query works? thanks in advance.
2
Answers
try using
groupBy('siswa_id')
on your query builder and see check the resultTry using count i believe, if the absence was another model or table and
Nama Lengkap
is came from the User, try use this:At the end of the day, this will lead with a new collection, you can find out how collection works in Laravel. And for looping, you can try using mapping or foreach loop for each of the data and use those array as an example. Another approach you can also use
withCount
but it will take another level if you want to filter out the results.