ajax()) { $model = Enquiry::query()->latest(); return DataTables::eloquent($model) ->addIndexColumn() ->setRowClass(function (Enquiry $enquiry) { return $enquiry->is_read ? 'text-muted' : 'text-dark'; }) ->editColumn('class', function (Enquiry $enquiry) { return $enquiry->class ?? '-'; }) ->editColumn('subject', function (Enquiry $enquiry) { return $enquiry->subject ?? '-'; }) ->editColumn('message', function (Enquiry $enquiry) { return $enquiry->message ?? '-'; }) ->addColumn('action', 'ccms::enquiry.datatable.action') ->rawColumns(['action']) ->toJson(); } return view('ccms::enquiry.index', [ 'title' => 'Enquiry List', ]); } public function booking() { if (request()->ajax()) { $model = Enquiry::query()->latest()->where('type', 'booking'); return DataTables::eloquent($model) ->addIndexColumn() ->setRowClass(function (Enquiry $enquiry) { return $enquiry->is_read ? 'text-muted' : 'text-dark'; }) ->editColumn('class', function (Enquiry $enquiry) { return $enquiry->class ?? '-'; }) ->editColumn('subject', function (Enquiry $enquiry) { return $enquiry->subject ?? '-'; }) ->editColumn('message', function (Enquiry $enquiry) { return $enquiry->message ?? '-'; }) ->addColumn('action', 'ccms::enquiry.datatable.action') ->rawColumns(['action']) ->toJson(); } return view('ccms::enquiry.index', [ 'title' => 'Booking List', ]); } /** * Show the form for creating a new resource. */ public function create() { // } /** * Store a newly created resource in storage. */ public function store(Request $request) { try { $rules = [ 'name' => 'required|string', 'email' => 'required|email', 'mobile' => 'nullable|numeric', 'subject' => 'nullable', 'class' => 'nullable', 'message' => 'nullable|max:250', ]; if (setting('enable_reCaptcha') == 1) { $rules['g-recaptcha-response'] = ['required', new Recaptcha]; } $messages = [ 'email.email' => 'Must be a valid email address.', 'mobile.numeric' => 'Must be a valid phone number.', 'mobile.digits' => 'Must be a valid phone number.', 'g-recaptcha-response.required' => 'Please complete reCAPTCHA validation.', 'g-recaptcha-response' => 'Invalid reCAPTCHA.', ]; $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return response()->json(['errors' => $validator->errors()], 422); } $validatedData = $validator->validated(); // $validatedData['type'] = 'enquiries'; // Set the type Enquiry::create($validatedData); // Enquiry::create($validator->validated()); return response()->json(['status' => 200, 'message' => "Thank you for reaching out! Your message has been received and we'll get back to you shortly."], 200); } catch (\Exception $e) { return response()->json(['status' => 500, 'message' => 'Internal server error', 'error' => $e->getMessage()], 500); } } // public function store(Request $request) // { // $rules = [ // 'name' => 'required|string', // 'email' => 'required|email', // 'mobile' => 'nullable|numeric|digits_between:7,15', // 'subject' => 'nullable|string|max:100', // 'message' => 'nullable|string|max:250', // ]; // if (setting('enable_reCaptcha') == 1) { // $rules['g-recaptcha-response'] = ['required', new Recaptcha]; // } // $validator = Validator::make($request->all(), $rules); // if ($validator->fails()) { // return response()->json(['errors' => $validator->errors()], 422); // } // Enquiry::create($validator->validated()); // return response()->json([ // 'status' => 200, // 'message' => "Thank you! We'll get back to you soon." // ], 200); // } /** * Show the specified resource. */ public function show($id) { // } /** * Show the form for editing the specified resource. */ public function edit($id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $enquiry = Enquiry::whereId($id)->first(); if ($enquiry) { $enquiry->delete(); } return response()->json(['status' => 200, 'message' => 'Enquiry has been deleted!'], 200); } catch (\Throwable $th) { return redirect()->back()->with('error', $th->getMessage()); } } public function markAsRead($id) { try { $enquiry = Enquiry::whereId($id)->first(); if ($enquiry) { $enquiry->update(['is_read' => 1]); } return response()->json(['status' => 200, 'message' => 'Enquiry has been marked as read!'], 200); } catch (\Throwable $th) { return redirect()->back()->with('error', $th->getMessage()); } } }