app/Http/Controllers/RekapController.php
/**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
Show the form for creating a new resource.
@return \Illuminate\Http\Response
Show the form for creating a new resource . @return \ Illuminate \ Http \ Response
public function hitung()
    {
        $rekap = Rekap::count();
        if ($rekap != 0) {
            Rekap::truncate();
        }
        $data = json_decode(DB::table('longsor')
            ->select('kecamatan', DB::raw('sum(kb_meninggal)+sum(kb_hilang)+sum(kb_luka)+sum(kb_mengungsi) as korban'), DB::raw('count(tgl) as kejadian'), DB::raw('sum(kr_rumah_rb)+sum(kr_rumah_rr)+sum(kr_rumah_terendam)+sum(kantor)+sum(sekolah)+sum(t_ibadah)+sum(sarana_kesehatan)+sum(bangunan_lain)+sum(jembatan)+sum(jalan)+sum(sawah)+sum(hutan) as kerusakan'))
            ->groupBy('kecamatan')->get(), true);
        $jml_data = DB::table('longsor')->select('kecamatan')->groupBy('kecamatan')->get()->count();
        for ($i = 0; $i < $jml_data; $i++) {
            Rekap::insert([
                'kecamatan' => $data[$i]['kecamatan'],
                'kejadian' => $data[$i]['kejadian'],
                'korban' => $data[$i]['korban'],
                'kerusakan' => $data[$i]['kerusakan'],
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ]);
        }
        return redirect()->route('rekap.index')->with('success', 'Data berhasil direkap ulang');
    }
public function hitung ( ) { $ rekap = Rekap :: count ( ) ; if ( $ rekap != 0 ) { Rekap :: truncate ( ) ; } $ data = json_decode ( DB :: table ( 'longsor' ) -> select ( 'kecamatan' , DB :: raw ( 'sum(kb_meninggal)+sum(kb_hilang)+sum(kb_luka)+sum(kb_mengungsi) as korban' ) , DB :: raw ( 'count(tgl) as kejadian' ) , DB :: raw ( 'sum(kr_rumah_rb)+sum(kr_rumah_rr)+sum(kr_rumah_terendam)+sum(kantor)+sum(sekolah)+sum(t_ibadah)+sum(sarana_kesehatan)+sum(bangunan_lain)+sum(jembatan)+sum(jalan)+sum(sawah)+sum(hutan) as kerusakan' ) ) -> groupBy ( 'kecamatan' ) -> get ( ) , true ) ; $ jml_data = DB :: table ( 'longsor' ) -> select ( 'kecamatan' ) -> groupBy ( 'kecamatan' ) -> get ( ) -> count ( ) ; for ( $ i = 0 ; $ i < $ jml_data ; $ i ++ ) { Rekap :: insert ( [ 'kecamatan' => $ data [ $ i ] [ 'kecamatan' ] , 'kejadian' => $ data [ $ i ] [ 'kejadian' ] , 'korban' => $ data [ $ i ] [ 'korban' ] , 'kerusakan' => $ data [ $ i ] [ 'kerusakan' ] , 'created_at' => date ( 'Y-m-d H:i:s' ) , 'updated_at' => date ( 'Y-m-d H:i:s' ) , ] ) ; } return redirect ( ) -> route ( 'rekap.index' ) -> with ( 'success' , 'Data berhasil direkap ulang' ) ; }
Show the form for creating a new resource.
Show the form for creating a new resource .
// ->pluck('total_korban', 'kecamatan');