ajax()) { $model = Franchise::query()->latest(); return DataTables::eloquent($model) ->addIndexColumn() ->addColumn('action', 'ccms::franchise.datatable.action') ->rawColumns(['action']) ->toJson(); } return view('ccms::franchise.index', [ 'title' => 'Franchise 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 = [ 'first_name' => 'required|string', 'email' => 'required|email', ]; if (setting('enable_reCaptcha') == 1) { $rules['g-recaptcha-response'] = ['required', new Recaptcha]; } $messages = [ 'email.email' => 'Must be a valid email address.', '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); } Franchise::create($request->all()); 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); } } /** * 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 { $franchise = Franchise::whereId($id)->first(); if ($franchise) { $franchise->delete(); } return response()->json(['status' => 200, 'message' => 'Franchise has been deleted!'], 200); } catch (\Throwable $th) { return redirect()->back()->with('error', $th->getMessage()); } } }