HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/sarvodayahospital/app/Http/Controllers/PreventiveHealthCheckupController.php
<?php

namespace App\Http\Controllers;

use App\Mail\PreventiveHealthCheckupMail;
use App\Models\CMSPage;
use App\Models\Hospital;
use App\Models\PreventiveHealthCheckup;
use App\Models\PreventiveHealthForm;
use Artesaos\SEOTools\Facades\SEOMeta;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use App\Models\Doctor;
use App\Models\Phc;
use Artesaos\SEOTools\Facades\OpenGraph;

class PreventiveHealthCheckupController extends Controller
{
    public function index()
    {
        $seo = [];

        $packages = PreventiveHealthCheckup::query()
            ->orderBy('Weight', 'ASC')
            ->get();

        $phc = Phc::first();

        $cmsPage = CMSPage::query()
            ->where('Slug', request()->path())
            ->firstOrFail();

        if ($cmsPage) {
            $seo = $cmsPage->seoComponent()->first();
        }

        return view('pages.phc', compact('packages', 'phc', 'seo'));
    }

    public function show($slug)
    {
        $package = PreventiveHealthCheckup::query()
            ->where('Slug', $slug)
            ->firstOrFail();

        $seo = [];

        if ($package) {
            $seo = $package->seoComponent()->first();
        }

        return view('pages.single-phc', compact('package', 'seo'));
    }

    public function healthPackageForm($slug)
    {
        $package = PreventiveHealthCheckup::query()
            ->with('hospitals')
            ->where('Slug', $slug)
            ->firstOrFail();

        $hospitals = Hospital::query()
            ->whereNotIn('Slug', ['sarvodaya-imaging-centre-with-nrch', 'sarvodaya-imaging-centre-with-ndmc'])
            ->orderBy('Weight', 'ASC')
            ->pluck('Slug', 'HospitalName');

        return view('pages.php-form', compact('package', 'hospitals'));
    }

    public function applyHealthPackage(Request $request)
    {
        $sourceURL = $request->source_url ?? $request->fullUrl();
        $extractedURL = extractURL($sourceURL);

        $rules = [
            'location' => 'required',
            'patient_name' => 'required',
            'patient_email' => 'required',
            'patient_phone' => 'required',
            'appointment_date' => 'required',
            'patient_gender' => 'required'
        ];

        $validator = Validator::make($request->all(), $rules);

        if ($validator->fails()) {
            return response()->json([
                'success' => false,
                'errors'  => $validator->getMessageBag()->toArray(),
                'status'  => 422
            ], 422);
        }

        $data = [
            'Name'             => $request->patient_name,
            'Email'            => $request->patient_email,
            'Phone'            => $request->patient_phone,
            'AppointmentDate'  => Carbon::parse($request->appointment_date)->format('Y-m-d'),
            'HospitalName'     => $request->location,
            'Gender'           => $request->patient_gender,
            'PackageName'      => $request->package_name,
            'Remark'           => $request->remark,
            'IPAddress'        => $request->ip(),
            'URL'              => array_key_exists('url', $extractedURL) ? $extractedURL['url'] : '',
            'Source'           => array_key_exists('utm_source', $extractedURL) ? $extractedURL['utm_source'] : '',
            'Campaign'         => array_key_exists('utm_campaign', $extractedURL) ? removeSpaceInQueryString($extractedURL['utm_campaign']) : '',
            'Medium'           => array_key_exists('utm_medium', $extractedURL) ? removeSpaceInQueryString($extractedURL['utm_medium']) : '',
            'published_at'     => Carbon::now()
        ];

        $package = PreventiveHealthForm::create($data);

        if (!$package) {
            return response()->json(['success' => false, 'message' => 'Something went wrong']);
        }

        # Send Mail
        Mail::to(config('sarvodaya.lead_recipient.to'))->send(new PreventiveHealthCheckupMail($data));

        return response()->json(['success' => true, 'message' => 'We will received your request.']);

    }
}