function($q){ $q->orderBy('updated_at', 'desc'); }])->where('no_siri',$no_siri)->first(); $curr = Carbon::now()->getTimestamp(); if(!empty($file->Investigation)){ foreach($file->Investigation as $a) { $n1 = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } array_push($nested_data, array( 'tarikh' => $n1.$a->updated_at->format('d/m/Y'), 'masa' => $a->updated_at->format('h:i A'), 'subjek' => $a->subjek, 'kategori' => $a->kategori, 'tindakan' => $a->_id )); } } return \DataTables::of($nested_data)->make(true); } public function deleteAttachment(Request $request) { $staff = Staff::with('StaffDetail')->where('_id',$request->staff)->first(); if(!empty($staff)){ $attach = Investigation::with('Attachment')->where('_id',$request->id)->first(); if(!empty($attach->Attachment)){ foreach($attach->Attachment as $a){ $a->delete(); } $attach->delete(); $file = ConfidentialFile::where('no_siri',$request->no_siri)->first(); $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $file->no_siri, 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini pengesahan kompaun ".$request->kpd, 'huraian' => "Rekod lampiran ".$attach->kategori." (".$attach->subjek.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." _id."/profile'>".$staff->StaffDetail->full_name.".", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $file->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $file->history()->attach($history); } return response()->json(['status' => 'true', 'desc' => 'Buang rekod lampiran ( '.$attach->subjek.' )']); }else{ return response()->json(['status' => 'false', 'desc' => 'Buang rekod lampiran ( '.$attach->subjek.' )']); } } } }