Controller.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Jenssegers\Agent\Agent;
  5. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  6. use Illuminate\Foundation\Bus\DispatchesJobs;
  7. use Illuminate\Foundation\Validation\ValidatesRequests;
  8. use Illuminate\Routing\Controller as BaseController;
  9. use Illuminate\Support\Facades\Mail;
  10. use App\Http\Traits\StringGeneratorTrait;
  11. use Ramsey\Uuid\Uuid;
  12. use App\Mail\NotifyEmail;
  13. use App\Models\WebForm;
  14. class Controller extends BaseController
  15. {
  16. use AuthorizesRequests, DispatchesJobs, ValidatesRequests, StringGeneratorTrait;
  17. public function sendWebsiteEmailNotification($details){
  18. if(config('app.env') == 'production'){
  19. $toUsers = [
  20. ['email' => config('app.supportEmailAddress'), 'name' => 'Hemband Support'],
  21. ['email' => config('app.adminEmailAddress'), 'name' => 'Hemband Admin'],
  22. ['email' => 'salshah497@gmail.com', 'name' => 'Sal Shah'],
  23. ['email' => 'hujaberi@gmail.com', 'name' => 'Hujaberi'],
  24. ['email' => 'shawn.shah@hemband.com', 'name' => 'Shawn Shah'],
  25. ['email' => 'robert.williams@hemband.com', 'name' => 'Robert Williams'],
  26. ['email' => 'nick.holden@hemband.com', 'name' => 'Nick Holden'],
  27. ['email' => 'adam.thomas@hemband.com', 'name' => 'Adam Thomas'],
  28. ];
  29. }else{
  30. $toUsers = [
  31. ['email' => config('app.testEmailAddress'), 'name' => 'Test Email Address']
  32. ];
  33. }
  34. Mail::to($toUsers)->send(new NotifyEmail($details));
  35. return true;
  36. }
  37. public function saveWebForm(Request $request){
  38. $data = $request->except(['form_name', '_token', 'g-recaptcha-response']);
  39. $agent = new Agent();
  40. $record = new WebForm;
  41. $record->iid = $this->makeIID();
  42. $record->uid = Uuid::uuid6();
  43. $record->form_name = $request->get('form_name');
  44. $record->ip_address = $request->ip();
  45. $record->device_type = $agent->device();
  46. $record->form_data = json_encode($data);
  47. $record->save();
  48. return $record;
  49. }
  50. }