You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					46 lines
				
				1.5 KiB
			
		
		
			
		
	
	
					46 lines
				
				1.5 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace App\Http\Controllers;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use App\Jobs\SendEnquiryMailJob;
							 | 
						||
| 
								 | 
							
								use App\Models\Country;
							 | 
						||
| 
								 | 
							
								use App\Models\Enquiry;
							 | 
						||
| 
								 | 
							
								use Illuminate\Http\Request;
							 | 
						||
| 
								 | 
							
								use Illuminate\Support\Facades\DB;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class EnquiryController extends Controller
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    public function form()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $countries = Country::all();
							 | 
						||
| 
								 | 
							
								        return view('enquiry-form', compact('countries'));
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function submit(Request $request)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $work_experience = $request->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);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |