Browse Source

Added web forms table

Samson Mutunga 2 years ago
parent
commit
5fe18bb928

+ 6 - 0
app/Http/Controllers/AppController.php

@@ -56,6 +56,8 @@ class AppController extends Controller
         'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
+      $request['form_name'] = 'patient_find_a_clinic';
+
       $record = new PatientFindAClinicRequest;
       $record->iid = $this->makeIID();
       $record->uid = Uuid::uuid6();
@@ -66,6 +68,7 @@ class AppController extends Controller
       $record->zip = $request->get('zip');
 
       $record->save();
+      $this->saveWebForm($request);
       $this->sendWebsiteEmailNotification([
         'template' => 'find-a-clinic',
         'subject' => 'Find a clinic request',
@@ -86,6 +89,8 @@ class AppController extends Controller
         'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
+      $request['form_name'] = 'patient_contact_message';
+
       $record = new PatientContactMessage;
       $record->iid = $this->makeIID();
       $record->uid = Uuid::uuid6();
@@ -98,6 +103,7 @@ class AppController extends Controller
       $record->message = $request->get('message');
 
       $record->save();
+      $this->saveWebForm($request);
       $this->sendWebsiteEmailNotification([
         'template' => 'contact',
         'subject' => $record->subject,

+ 20 - 1
app/Http/Controllers/Controller.php

@@ -2,16 +2,21 @@
 
 namespace App\Http\Controllers;
 
+use Illuminate\Http\Request;
+use Jenssegers\Agent\Agent;
 use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Support\Facades\Mail;
+use App\Http\Traits\StringGeneratorTrait;
+use Ramsey\Uuid\Uuid;
 use App\Mail\NotifyEmail;
+use App\Models\WebForm;
 
 class Controller extends BaseController
 {
-    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, StringGeneratorTrait;
 
     public function sendWebsiteEmailNotification($details){   
         $toUsers = [
@@ -21,4 +26,18 @@ class Controller extends BaseController
         Mail::to($toUsers)->send(new NotifyEmail($details));
         return true;
     }
+
+    public function saveWebForm(Request $request){
+        $data = $request->except(['form_name', '_token', 'g-recaptcha-response']);
+        $agent = new Agent();
+        $record = new WebForm;
+        $record->iid = $this->makeIID();
+        $record->uid = Uuid::uuid6();
+        $record->form_name = $request->get('form_name');
+        $record->ip_address = $request->ip();
+        $record->device_type = $agent->device();;
+        $record->form_data = json_encode($data);
+
+        $record->save();
+    }
 }

+ 18 - 0
app/Http/Controllers/PhysiciansController.php

@@ -81,6 +81,8 @@ class PhysiciansController extends Controller
         'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
+      $request['form_name'] = 'physician_training_request';
+
       $record = new PhysicianTrainingRequest;
       $record->iid = $this->makeIID();
       $record->uid = Uuid::uuid6();
@@ -96,6 +98,7 @@ class PhysiciansController extends Controller
       $record->notes = $request->get('notes');
 
       $record->save();
+      $this->saveWebForm($request);
 
       $this->sendWebsiteEmailNotification([
         'template' => 'training-request',
@@ -118,6 +121,8 @@ class PhysiciansController extends Controller
         'message' => 'required|string',
       ]);
 
+      $request['form_name'] = 'physician_contact_message';
+
       $record = new PhysicianContactMessage;
       $record->iid = $this->makeIID();
       $record->uid = Uuid::uuid6();
@@ -131,6 +136,8 @@ class PhysiciansController extends Controller
       $record->message = $request->get('message');
 
       $record->save();
+      $this->saveWebForm($request);
+
       $this->sendWebsiteEmailNotification([
         'template' => 'physician-contact',
         'subject' => 'Hemband Physician Contact Form',
@@ -152,6 +159,8 @@ class PhysiciansController extends Controller
         'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
+      $request['form_name'] = 'physician_directory_listing_request';
+
       $record = new PhysicianDirectoryListingRequest;
       $record->iid = $this->makeIID();
       $record->uid = Uuid::uuid6();
@@ -165,6 +174,8 @@ class PhysiciansController extends Controller
       $record->comment = $request->get('comment');
 
       $record->save();
+      $this->saveWebForm($request);
+
       $this->sendWebsiteEmailNotification([
         'template' => 'physician-directory-listing-request',
         'subject' => 'Hemband Physician Directory Listing Request Form',
@@ -186,6 +197,8 @@ class PhysiciansController extends Controller
         'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
+      $request['form_name'] = 'physician_marketing_materials_request';
+
       $record = new PhysicianMarketingMaterialsRequest;
       $record->iid = $this->makeIID();
       $record->uid = Uuid::uuid6();
@@ -200,6 +213,8 @@ class PhysiciansController extends Controller
       $record->comment = $request->get('comment');
 
       $record->save();
+      $this->saveWebForm($request);
+
       $this->sendWebsiteEmailNotification([
         'template' => 'physician-marketing-materials-request',
         'subject' => 'Hemband Physician Marketing Materials Request Form',
@@ -223,6 +238,8 @@ class PhysiciansController extends Controller
         'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
+      $request['form_name'] = 'physician_ligator_order';
+
       $record = new LigatorOrder;
       $record->iid = $this->makeIID();
       $record->uid = Uuid::uuid6();
@@ -245,6 +262,7 @@ class PhysiciansController extends Controller
       $record->delivery_option = $request->get('delivery_option');
       $record->agrees_to_terms = $request->get('agrees_to_terms');
       $record->save();
+      $this->saveWebForm($request);
 
       $this->sendWebsiteEmailNotification([
         'template' => 'physician-order-ligators',

+ 11 - 0
app/Models/WebForm.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use App\Models\Base\BaseModel;
+use Illuminate\Database\Eloquent\Model;
+
+class WebForm extends BaseModel
+{
+    protected $table = 'web_form';
+}

+ 1 - 0
composer.json

@@ -9,6 +9,7 @@
         "biscolab/laravel-recaptcha": "^5.4",
         "fruitcake/laravel-cors": "^2.0",
         "guzzlehttp/guzzle": "^7.0.1",
+        "jenssegers/agent": "^2.6",
         "laravel/framework": "^8.75",
         "laravel/sanctum": "^2.11",
         "laravel/tinker": "^2.5"

+ 192 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "d994c8882a79491311ca56c8b9d912d4",
+    "content-hash": "de17b7d4652cdfb07133cf4c35fe14a6",
     "packages": [
         {
             "name": "asm89/stack-cors",
@@ -1036,6 +1036,141 @@
             ],
             "time": "2022-08-28T14:45:39+00:00"
         },
+        {
+            "name": "jaybizzle/crawler-detect",
+            "version": "v1.2.112",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/JayBizzle/Crawler-Detect.git",
+                "reference": "2c555ce35a07a5c1c808cee7d5bb52c41a4c7b2f"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/2c555ce35a07a5c1c808cee7d5bb52c41a4c7b2f",
+                "reference": "2c555ce35a07a5c1c808cee7d5bb52c41a4c7b2f",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8|^5.5|^6.5|^9.4"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Jaybizzle\\CrawlerDetect\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Mark Beech",
+                    "email": "m@rkbee.ch",
+                    "role": "Developer"
+                }
+            ],
+            "description": "CrawlerDetect is a PHP class for detecting bots/crawlers/spiders via the user agent",
+            "homepage": "https://github.com/JayBizzle/Crawler-Detect/",
+            "keywords": [
+                "crawler",
+                "crawler detect",
+                "crawler detector",
+                "crawlerdetect",
+                "php crawler detect"
+            ],
+            "support": {
+                "issues": "https://github.com/JayBizzle/Crawler-Detect/issues",
+                "source": "https://github.com/JayBizzle/Crawler-Detect/tree/v1.2.112"
+            },
+            "time": "2022-10-05T21:52:44+00:00"
+        },
+        {
+            "name": "jenssegers/agent",
+            "version": "v2.6.4",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/jenssegers/agent.git",
+                "reference": "daa11c43729510b3700bc34d414664966b03bffe"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/jenssegers/agent/zipball/daa11c43729510b3700bc34d414664966b03bffe",
+                "reference": "daa11c43729510b3700bc34d414664966b03bffe",
+                "shasum": ""
+            },
+            "require": {
+                "jaybizzle/crawler-detect": "^1.2",
+                "mobiledetect/mobiledetectlib": "^2.7.6",
+                "php": ">=5.6"
+            },
+            "require-dev": {
+                "php-coveralls/php-coveralls": "^2.1",
+                "phpunit/phpunit": "^5.0|^6.0|^7.0"
+            },
+            "suggest": {
+                "illuminate/support": "Required for laravel service providers"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.0-dev"
+                },
+                "laravel": {
+                    "providers": [
+                        "Jenssegers\\Agent\\AgentServiceProvider"
+                    ],
+                    "aliases": {
+                        "Agent": "Jenssegers\\Agent\\Facades\\Agent"
+                    }
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Jenssegers\\Agent\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Jens Segers",
+                    "homepage": "https://jenssegers.com"
+                }
+            ],
+            "description": "Desktop/mobile user agent parser with support for Laravel, based on Mobiledetect",
+            "homepage": "https://github.com/jenssegers/agent",
+            "keywords": [
+                "Agent",
+                "browser",
+                "desktop",
+                "laravel",
+                "mobile",
+                "platform",
+                "user agent",
+                "useragent"
+            ],
+            "support": {
+                "issues": "https://github.com/jenssegers/agent/issues",
+                "source": "https://github.com/jenssegers/agent/tree/v2.6.4"
+            },
+            "funding": [
+                {
+                    "url": "https://github.com/jenssegers",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/jenssegers/agent",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2020-06-13T08:05:20+00:00"
+        },
         {
             "name": "laravel/framework",
             "version": "v8.83.25",
@@ -1740,6 +1875,62 @@
             ],
             "time": "2022-04-17T13:12:02+00:00"
         },
+        {
+            "name": "mobiledetect/mobiledetectlib",
+            "version": "2.8.41",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/serbanghita/Mobile-Detect.git",
+                "reference": "fc9cccd4d3706d5a7537b562b59cc18f9e4c0cb1"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/fc9cccd4d3706d5a7537b562b59cc18f9e4c0cb1",
+                "reference": "fc9cccd4d3706d5a7537b562b59cc18f9e4c0cb1",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.0.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.8.35||~5.7"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "Detection": "namespaced/"
+                },
+                "classmap": [
+                    "Mobile_Detect.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Serban Ghita",
+                    "email": "serbanghita@gmail.com",
+                    "homepage": "http://mobiledetect.net",
+                    "role": "Developer"
+                }
+            ],
+            "description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.",
+            "homepage": "https://github.com/serbanghita/Mobile-Detect",
+            "keywords": [
+                "detect mobile devices",
+                "mobile",
+                "mobile detect",
+                "mobile detector",
+                "php mobile detect"
+            ],
+            "support": {
+                "issues": "https://github.com/serbanghita/Mobile-Detect/issues",
+                "source": "https://github.com/serbanghita/Mobile-Detect/tree/2.8.41"
+            },
+            "time": "2022-11-08T18:31:26+00:00"
+        },
         {
             "name": "monolog/monolog",
             "version": "2.8.0",

+ 4 - 0
config/app.php

@@ -187,6 +187,8 @@ return [
         App\Providers\EventServiceProvider::class,
         App\Providers\RouteServiceProvider::class,
 
+        Jenssegers\Agent\AgentServiceProvider::class,
+
     ],
 
     /*
@@ -242,6 +244,8 @@ return [
         'Validator' => Illuminate\Support\Facades\Validator::class,
         'View' => Illuminate\Support\Facades\View::class,
 
+        'Agent' => Jenssegers\Agent\Facades\Agent::class,
+
     ],
 
 ];

+ 37 - 0
database/migrations/2022_12_14_151406_create_web_form_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateWebFormTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('web_form', function (Blueprint $table) {
+            $table->id();
+            $table->string('uid')->unique();
+            $table->string('iid')->unique();
+            $table->string('form_name')->nullable();
+            $table->string('ip_address')->nullable();
+            $table->string('device_type')->nullable();
+            $table->jsonb('form_data')->nullable();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('web_form');
+    }
+}