title; $data['route'] = $this->route; return view($this->template.'.index', $data); } /** * Show the form for creating a new resource. */ public function create() { // } public function grid(Request $request) { if(session('group_alias') == 'sekolah'){ $data = SampahTerkelola::where('ms_sekolah_id',session('sekolah_id')) ->orderBy('tahun','DESC') ->orderBy('bulan','ASC'); }else{ if(session('kabupaten_id') != ''){ $data = SampahTerkelola::whereHas('sekolah',function($query){ $query->where('ms_kabupaten_id',session('kabupaten_id')); })->orderBy('tahun','DESC') ->orderBy('bulan','ASC'); }else{ $data = SampahTerkelola::with(['sekolah'])->orderBy('tahun','DESC') ->orderBy('bulan','ASC'); } } if(@request()->tahun){ $tahun = request()->tahun; }else{ $tahun = date('Y'); } $data->where('tahun',$tahun); $_data = []; foreach ($data->get() as $key => $row) { $sekolah = ''; $sekolah .= @$row->sekolah->nama_sekolah.'
'; $sekolah .= ''.@$row->sekolah->profile->tingkat->name.' '; $sekolah .= ''.@$row->sekolah->profile->status_sekolah.' '; $sekolah .= 'Level '.levelAdiwiyata($row->sekolah->npsn).''; $sekolah .= ''.@$row->sekolah->profile->alamat_sekolah.' '; $_data[] = [ 'no' => $key+1, 'id' => encode_id($row->SampahTekelolaId), 'tahun' => $row->tahun, 'sekolah' => $sekolah, 'bulan' => monthtString($row->bulan), 'organik' => $row->organik, 'sampah_anorganik' => $row->sampah_anorganik, 'b3' => $row->b3, 'minyak_jelantah' => $row->minyak_jelantah, ]; } // return response()->json($_data); // Return the data as a JSON response return response()->json($_data); } /** * Store a newly created resource in storage. */ public function store(Request $request) { try { $data = SampahTerkelola::updateOrCreate([ 'tahun' => date('Y'), 'bulan' => $request->bulan, 'ms_sekolah_id' => session('sekolah_id'), ],[ 'tahun' => date('Y'), 'ms_sekolah_id' => session('sekolah_id'), 'bulan' => $request->bulan, 'organik' => $request->organik, 'sampah_anorganik' => $request->anorganik, 'b3' => $request->b3, 'minyak_jelantah' => $request->minyak_jelantah, ]); return redirect()->back()->with([ 'message' => 'Berhasil update data', 'type' => 'success', ]); } catch (\Throwable $th) { //throw $th; dd($th); } } /** * Display the specified resource. */ public function show(string $id) { // } /** * Show the form for editing the specified resource. */ public function edit(string $id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }