ajax()) { $model = Vacancy::query()->latest(); return DataTables::eloquent($model) ->addIndexColumn() // ->setRowClass(function (Vacancy $vacancy) { // return $vacancy->is_read ? 'text-muted' : 'text-dark'; // }) // ->editColumn('class', function (Vacancy $vacancy) { // return $vacancy->class ?? '-'; // }) // ->editColumn('subject', function (Vacancy $vacancy) { // return $vacancy->subject ?? '-'; // }) // ->editColumn('message', function (Vacancy $vacancy) { // return $vacancy->message ?? '-'; // }) ->addColumn('action', 'ccms::vacancy.datatable.action') ->rawColumns(['action']) ->toJson(); } return view('ccms::vacancy.index', [ 'title' => 'Vacancy 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 = [ // ]; // 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()); // if ($validator->fails()) { // return response()->json(['errors' => $validator->errors()], 422); // } $modelClass = "Modules\\CCMS\\Models\\Career"; $model = $modelClass::findOrFail($request->career_id); foreach ($request->document as $file) { $model->addToDocumentCollection(collectionName: 'uploads/document', file: $file, documentName: $request->first_name, referenceDocumentId: null); } Vacancy::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 { $vacancy = Vacancy::whereId($id)->first(); if ($vacancy) { $vacancy->delete(); } return response()->json(['status' => 200, 'message' => 'Vacancy has been deleted!'], 200); } catch (\Throwable $th) { return redirect()->back()->with('error', $th->getMessage()); } } public function markAsRead($id) { try { $vacancy = Vacancy::whereId($id)->first(); if ($vacancy) { $vacancy->update(['is_read' => 1]); } return response()->json(['status' => 200, 'message' => 'Vacancy has been marked as read!'], 200); } catch (\Throwable $th) { return redirect()->back()->with('error', $th->getMessage()); } } }