EmailTestController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\File;
  5. use App\Http\Services\EmailService;
  6. use App\Models\PromoCode;
  7. use App\Models\StoreOrder;
  8. use App\Models\User;
  9. class EmailTestController extends Controller
  10. {
  11. public $appUrl;
  12. protected $emailService;
  13. public $appInternalName;
  14. public $stringMappingConfig;
  15. public function __construct(EmailService $emailService)
  16. {
  17. parent::__construct();
  18. $this->appUrl = config('app.url');
  19. $this->emailService = $emailService;
  20. $this->appInternalName = config('app.internalName');
  21. $this->stringMappingConfig = config('constants.' . $this->appInternalName );
  22. }
  23. public function previewEmail($email = null)
  24. {
  25. if(!$this->user->is_super_admin){
  26. abort(403);
  27. }
  28. $appInternalName = $this->appInternalName;
  29. $stringMappingConfig = $this->stringMappingConfig;
  30. if($email){
  31. $destinationPath = resource_path('views/emails/templates/' . $email . '.blade.php');
  32. if(File::exists($destinationPath)){
  33. $content = File::get($destinationPath);
  34. $user = $this->user;
  35. $appUrl = $this->appUrl;
  36. $emailFromName = '[EMAIL_FROM_NAME]';
  37. $storeOrder = StoreOrder::first();
  38. $emailData = [
  39. 'to' => 'abc@def.com',
  40. 'suject' => '',
  41. 'content' => 'Some content'
  42. ];
  43. return view('emails/templates/' . $email, compact('user', 'emailData', 'appUrl', 'stringMappingConfig', 'appInternalName', 'emailFromName', 'storeOrder',));
  44. }
  45. else {
  46. abort(404);
  47. }
  48. }
  49. $files = File::allFiles(resource_path('views/emails/templates/'));
  50. $fileNames = [];
  51. foreach ($files as $file) {
  52. $fileName = $file->getFilename();
  53. $fileNameParts = explode('.', $fileName);
  54. $fileRef = @$fileNameParts[0];
  55. if($fileRef) array_push($fileNames, $fileRef);
  56. }
  57. return view('app.preview-email', compact('fileNames'));
  58. }
  59. }