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.
 
 
 
 

77 lines
2.4 KiB

<?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;
use Illuminate\Support\Facades\Session;
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);
}
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');
}
}