From 263ed94ab4c99c42ff935d31caafba3a323894d7 Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 27 Feb 2024 10:48:41 +0700 Subject: [PATCH] Contact Sales --- .../Controllers/ContactSalesController.php | 115 ++++++++++++++++++ app/Models/ContactSales.php | 27 ++++ 2 files changed, 142 insertions(+) create mode 100644 app/Http/Controllers/ContactSalesController.php create mode 100644 app/Models/ContactSales.php diff --git a/app/Http/Controllers/ContactSalesController.php b/app/Http/Controllers/ContactSalesController.php new file mode 100644 index 0000000..bfe4521 --- /dev/null +++ b/app/Http/Controllers/ContactSalesController.php @@ -0,0 +1,115 @@ +validate($request, [ + 'name' => 'required', + 'role' => 'required', + 'email' => 'required', + 'number_phone' => 'required', + 'status' => 'required', + ]); + + $data = $request->all(); + + $data['created_by'] = '@System'; + $data['status'] = 'New Request'; + + $result = ContactSales::create($data); + + if ($result) { + return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Your message has been successfully received by our Sales team! Someone from our team will be in touch with you shortly.', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Your message has been failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $result = ContactSales::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data Contact Sales, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ContactSales::find($id); + + + if ($data) { + $result = $data->update($request->all()); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400); + die(); + } + + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed updated!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ContactSales::find($id); + + if ($data) { + $delete = $data->delete(); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400); + die(); + } + + + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed deleted!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_contact_sales'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ContactSales::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list Contact Sales, please try again later!', 'code' => 400], 400); + } + } +} diff --git a/app/Models/ContactSales.php b/app/Models/ContactSales.php new file mode 100644 index 0000000..9707bb9 --- /dev/null +++ b/app/Models/ContactSales.php @@ -0,0 +1,27 @@ +