i'm newbie to laravel. I want to count the number with where condition in column 'ket'. In this code, i've successfully applied to normal user (code 1), i want to applied the code 1 $total_tdkmsk $total_msk $total_telat
into code 2. So this is what i've done.
Laravel Fluent Query
$id_alias = Auth::user()->id;
$tdkmsk = 'Tidak Masuk';
$msk = 'Masuk';
$total_tdkmsk = DB::table('presensi')
-> where('presensi.ket','=',$tdkmsk)
-> where('presensi.id_user','=',$id_alias)
-> count();
$total_msk = DB::table('presensi')
-> where('presensi.ket','=',$msk)
-> where('presensi.id_user','=',$id_alias)
-> count();
$total_telat = DB::table('presensi')
-> where('presensi.id_user','=',$id_alias)
-> sum('ketidakhadiran');
into this query
$items = DB::table('presensi')
->join('jabatan', 'presensi.id_user', '=', 'jabatan.id')
->join('users', 'presensi.id_user', '=', 'users.id')
->join('jadwal', 'presensi.jadwal', '=', 'jadwal.id')
->join('matakuliah', 'jadwal.id', '=', 'matakuliah.id')
->join('mahasiswakelas', 'jadwal.id_kelas', '=', 'mahasiswakelas.id_kelas')
->join('kelas', 'mahasiswakelas.id_kelas', '=', 'kelas.id')
->select('users.id AS id_users','users.name AS nama_users' ,'presensi.id AS id','jabatan.id AS id_jabatan','presensi.*', 'matakuliah.namamatakuliah','jabatan.nama_jabatan','kelas.nama_kelas','mahasiswakelas.tahunakademik',DB::raw('COUNT(*) as tidakada'))
-> where('presensi.ket','=',$tdkmsk)
->orderby('presensi.id', 'DESC')
->groupby('presensi.id_user')
->get();
I get the result, but this is not what i'm expected. Any advice for this? thank you very much