0){ $dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); }else{ return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); } } public function delete($id) { if($id && $id!="" && (int)$id > 0){ $dokumen = ActivityDokumen::find($id); if($dokumen){ if(file_exists($this->pathActivityDocument.$dokumen->file)){ unlink($this->pathActivityDocument.$dokumen->file); } $dokumen->delete(); return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); }else{ return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); } }else{ return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); } } public function uploadProjectDokumen(Request $request) { if($request->hasFile('dokumen')){ $activity_id = $request->activity_id; $dokumen = $request->file('dokumen'); $extension = $dokumen->extension(); $name = $dokumen->getClientOriginalName(); $result = $dokumen->move($this->pathActivityDocument, $name); if($result){ $data = [ 'activity_id' => (int)$activity_id, 'file' => $name, 'description' => $request->description ]; $result = ActivityDokumen::create($data); if($result){ return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200); }else{ unlink($this->pathActivityDocument.$name); return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); } }else{ return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); } }else{ return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); } } public function searchDocProject(Request $request){ // payload same like in goland API oke $payload = $request->all(); // second parameter is table name $dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); // builder for get data $builder = $dataBuilder['builder']; // builder for count data $countBuilder = $dataBuilder['count']; // execute builder $dataGet = $builder->get(); // execute count builder $totalRecord = $countBuilder->count(); // send response about the result return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); } public function downloadDokumen($id) { if($id && $id!="" && (int)$id > 0){ $dokumen = ActivityDokumen::find($id); if($dokumen){ if(file_exists($this->pathActivityDocument.$dokumen->file)){ $pathToFile = $this->pathActivityDocument.$dokumen->file; return response()->download($pathToFile); }else{ return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); } }else{ return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); } }else{ return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); } } }