resSuccess(null, $res_status, $msg, $status_msg, $result); }else { $res_status = false; $msg = 'Data tidak ditemukan'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, null); } } public function getByUser($user_id) { $query = Timeline::where('user_id', Helper::hash($user_id, 'decode'))->get(); if($query){ $result = $query; $res_status = true; $msg = 'Mendapatkan Data'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, $result); }else { $res_status = false; $msg = 'Data tidak ditemukan'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, null); } } public function getSingle($data_id) { $query = Timeline::where('id', Helper::hash($data_id, 'decode'))->get(); if($query){ $result = $query; $res_status = true; $msg = 'Mendapatkan Data'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, $result); }else { $res_status = false; $msg = 'Data tidak ditemukan'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, null); } } public function postStore(Request $request) { $post = $request->all(); // $file = $request->file('gambar'); //dd($post); /**digunakan untuk set rule validator */ $rules = [ 'gambar' => 'required', 'user_id' => 'required', // 'gambar' => 'required|file|max:1000', ]; /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */ // $alert = [ // 'file' => 'File maksimal 1MB' // ]; // $validator = Validator::make($post, $rules, $alert); $validator = Validator::make($post, $rules); if ($validator->passes()) { /**menggunakan transaction */ DB::beginTransaction(); // $nama_file = time()."_".$file->getClientOriginalName(); // $tujuan_upload = 'gambar'; // //$file->move($tujuan_upload,$nama_file); // Storage::putFileAs('public/images/Timeline/', $file, $nama_file ); $query = new Timeline(); $query->is_approved = 'pending'; $query->caption = $request->caption; $query->timeline_photo = Helper::base64_to_image($request->gambar, 'timeline'); $query->user_id = Helper::hash(Request::all()['user_id'], 'decode'); $query->save(); $query->hash_id = Helper::hash($query->id, 'encode'); $query->user_id = Helper::hash($query->user_id, 'encode'); if($query){ $result = $query; $res_status = true; $msg = 'Mendapatkan Data'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, $result); }else { $res_status = false; $msg = 'Data tidak ditemukan'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, null); } } } public function postUpdate(Request $request) { $post = $request->all(); $rules = [ 'id' => 'required', 'gambar' => 'required', 'user_id' => 'required', ]; $validator = Validator::make($post, $rules); if(!$validator->fails()){ $Timeline = Timeline::where('id', Helper::hash(Request::all()['id'], 'decode'))->firstOrFail(); $Timeline->name = $request->name; $Timeline->Timeline_identity = $request->Timeline_identity; $Timeline->Timeline_type = $request->Timeline_type; $Timeline->Timeline_photo = Helper::base64_to_image($request->gambar, 'Timeline'); $Timeline->user_id = Helper::hash(Request::all()['user_id'], 'decode'); $Timeline->save(); $Timeline->hash_id = Helper::hash($Timeline->id, 'encode'); $Timeline->user_id = Helper::hash($Timeline->user_id, 'encode'); $result = $Timeline; $res_status = true; $msg = 'Berhasil membuat user'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, $result); }else { $res_status = false; $msg = 'Gagal Membuat user'; $status_msg = $validator->errors(); return $this->resSuccess(null, $res_status, $msg, $status_msg, null); } } public function delete() { $validator = Validator::make(Request::all(), [ 'id' => ['required'], ]); if(!$validator->fails()){ $query = Timeline::find(Helper::hash(Request::all()['id'], 'decode'))->detroy(); if($query){ $result = $query; $res_status = true; $msg = 'Data berhasil dihapus'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, $result); }else{ $result = $query; $res_status = false; $msg = 'Data gagal dihapus'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, $result); } }else{ $res_status = false; $msg = 'Data tidak ditemukan'; $status_msg = $validator->errors(); return $this->resSuccess(null, $res_status, $msg, $status_msg, null); } if($query){ $result = $query; $res_status = true; $msg = 'Mendapatkan Data'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, $result); }else { $res_status = false; $msg = 'Data tidak ditemukan'; $status_msg = $msg; return $this->resSuccess(null, $res_status, $msg, $status_msg, null); } } public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null) { $response['response'] = array( 'status' => $status, 'message' => $msg, 'status_msg' => $status_msg, ); $response['param'] = !empty($param) ? $param : ''; $response['results'] = $result; return response()->json($response, 200); } }