EmailTestController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. $appInternalName = $this->appInternalName;
  26. $stringMappingConfig = $this->stringMappingConfig;
  27. if($email){
  28. $destinationPath = resource_path('views/emails/templates/' . $email . '.blade.php');
  29. if(File::exists($destinationPath)){
  30. $content = File::get($destinationPath);
  31. $user = $this->user;
  32. $appUrl = $this->appUrl;
  33. $emailFromName = '[EMAIL_FROM_NAME]';
  34. $storeOrder = StoreOrder::first();
  35. return view('emails/templates/' . $email, compact('user', 'appUrl', 'stringMappingConfig', 'appInternalName', 'emailFromName', 'storeOrder',));
  36. }
  37. else {
  38. abort(404);
  39. }
  40. }
  41. $files = File::allFiles(resource_path('views/emails/templates/'));
  42. $fileNames = [];
  43. foreach ($files as $file) {
  44. $fileName = $file->getFilename();
  45. $fileNameParts = explode('.', $fileName);
  46. $fileRef = @$fileNameParts[0];
  47. if($fileRef) array_push($fileNames, $fileRef);
  48. }
  49. return view('app.preview-email', compact('fileNames'));
  50. }
  51. }