How to create grouping with 2 field in laravel

Viewed 19

Anyone knows how to create grouping with 2 field or more ?

I have table category item and table work team. I want to display the total items by type of item and work team.

My Relation Table relation table

My expectation result is like this :

PC Unit Laptop
Workteam A 34 20
Workteam B 42 10

I've tried to build with my code, but I can't solve it yet.

My Query in Controller

$rekap         = RiwayatBarang::select('tim_kerja', 'kategori_barang', DB::raw('count(kategori_barang_id) as total_barang'))
            ->join('oldat_tbl_barang', 'oldat_tbl_barang.id_barang', 'oldat_tbl_riwayat_barang.barang_id')
            ->leftjoin('oldat_tbl_kategori_barang', 'oldat_tbl_kategori_barang.id_kategori_barang', 'oldat_tbl_barang.kategori_barang_id')
            ->join('tbl_pegawai', 'tbl_pegawai.id_pegawai', 'oldat_tbl_barang.pegawai_id')
            ->join('tbl_tim_kerja', 'tbl_tim_kerja.id_tim_kerja', 'tbl_pegawai.tim_kerja_id')
            ->groupBy('tim_kerja', 'kategori_barang')
            ->get();

            return view('v_super_user.apk_oldat.daftar_rekap', compact('totalKategori','rekap'));

I need help please, i don't know how to use grouping with more than 1 table.

0 Answers
Related