get('work_experience'); if ($work_experience == 'no') { $request['work_experience_details'] = null; $request['salary_mode'] = null; } $marital_status = $request->get('marital_status'); if ($marital_status == 'Widow' || $marital_status == 'Single') { $request['married_date'] = null; $request['spouse_academics'] = null; $request['spouse_work_experience'] = null; $request['spouse_salary_mode'] = null; } DB::beginTransaction(); try { $enquiry = Enquiry::create($request->all()); } catch (\Exception $e) { DB::rollback(); return redirect()->back()->with(['msg' => 'Something went wrong. Please try again!', 'status' => false], 400); } DB::commit(); dispatch(new SendEnquiryMailJob($enquiry)); return redirect()->back()->with(['msg' => 'We have recieved your enquiry. You will be contacted soon!', 'status' => true], 200); } public function index() { $enquiries = Enquiry::orderBy('id', 'DESC'); if (\request('name')) { $key = \request('name'); $enquiries = $enquiries->where('first_name', 'like', $key . '%'); } if (\request('email')) { $key = \request('email'); $enquiries = $enquiries->where('email', 'like', $key . '%'); } $enquiries = $enquiries->paginate(30); return view('admin.enquiry.index', compact('enquiries')); } public function show($id) { $enquiry = Enquiry::findorfail($id); return view('admin.enquiry.show', compact('enquiry')); } public function delete($id) { $enquiry = Enquiry::findorfail($id); $enquiry->delete(); Session::flash('success', 'Enquiry has been successfully deleted!'); return redirect('admin/enquiries'); } }