middleware('auth'); } public function getNotification($id_tahun_program_detail) { $tahunProgramDetail = TahunProgramDetail::find($id_tahun_program_detail); $user = Auth::user(); if (Role::where('id',Auth::user()->role_id)->value('akses') == 'administrator') { $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program) ->where('id_template_program_detail',$tahunProgramDetail->id_template_program_detail) ->orderBy('id','desc') ->get(); }else{ $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program) ->where('id_template_program_detail',$tahunProgramDetail->id_template_program_detail) ->where('id_upt',$user->upt) ->orderBy('id','desc') ->get(); } $html = ''; $id = ''; foreach ($getNotification as $notification) { $program = !empty($tahunProgramDetail->templateProgram)?$tahunProgramDetail->templateProgram->nama:'-'; $sub_program = !empty($tahunProgramDetail->templateProgramDetail)?$tahunProgramDetail->templateProgramDetail->nama:'-'; if ($notification != '') { $html .= ''.$program.''.$notification->message.''.$notification->created_at.''; $id .= $notification->id.','; } else{ $html = 'Tidak Ada Pemberitahuan'; } } return response()->json(['html' => $html,'id' => $id]); } public function updateToRead($id_tahun_program_detail) { $ok = 'false'; $tahunProgramDetail = TahunProgramDetail::find($id_tahun_program_detail); $user = Auth::user(); if (Role::where('id',Auth::user()->role_id)->value('akses') == 'administrator') { $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program) ->where('id_template_program',$tahunProgramDetail->id_template_program) ->pluck('id'); }else{ $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program) ->where('id_template_program',$tahunProgramDetail->id_template_program) ->where('id_upt',$user->upt) ->pluck('id'); } foreach($getNotification as $notif_id){ $attribute = [ 'id_user'=> $user->id, 'id_metadata_program_notification'=> $notif_id, ]; MetadataProgramNotificationRead::updateOrCreate($attribute,$attribute); $ok = 'true'; } return $ok; } }