MailSettings.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Settings;
  3. use Spatie\LaravelSettings\Settings;
  4. class MailSettings extends Settings
  5. {
  6. public ?string $mail_host;
  7. public ?int $mail_port;
  8. public ?string $mail_username;
  9. public ?string $mail_password;
  10. public ?string $mail_encryption;
  11. public ?string $mail_from_address;
  12. public ?string $mail_from_name;
  13. public ?string $mail_mailer;
  14. public static function group(): string
  15. {
  16. return 'mail';
  17. }
  18. public static function encrypted(): array
  19. {
  20. return [
  21. 'mail_password',
  22. ];
  23. }
  24. public function setConfig()
  25. {
  26. try {
  27. config()->set('mail.mailers.smtp.host', $this->mail_host);
  28. config()->set('mail.mailers.smtp.port', $this->mail_port);
  29. config()->set('mail.mailers.smtp.encryption', $this->mail_encryption);
  30. config()->set('mail.mailers.smtp.username', $this->mail_username);
  31. config()->set('mail.mailers.smtp.password', $this->mail_password);
  32. config()->set('mail.from.address', $this->mail_from_address);
  33. config()->set('mail.from.name', $this->mail_from_name);
  34. } catch (\Exception) {
  35. }
  36. }
  37. /**
  38. * Summary of validations array
  39. * @return array<string, string>
  40. */
  41. public static function getValidations()
  42. {
  43. return [
  44. 'mail_host' => 'nullable|string',
  45. 'mail_port' => 'nullable|int',
  46. 'mail_username' => 'nullable|string',
  47. 'mail_password' => 'nullable|string',
  48. 'mail_encryption' => 'nullable|string',
  49. 'mail_from_address' => 'nullable|string',
  50. 'mail_from_name' => 'nullable|string',
  51. 'mail_mailer' => 'nullable|string',
  52. ];
  53. }
  54. /**
  55. * Summary of optionTypes
  56. * Only used for the settings page
  57. * @return array<array<'type'|'label'|'description'|'options', string|bool|float|int|array<string, string>>>
  58. */
  59. public static function getOptionInputData()
  60. {
  61. return [
  62. 'category_icon' => 'fas fa-envelope',
  63. 'mail_host' => [
  64. 'label' => 'Mail Host',
  65. 'type' => 'string',
  66. 'description' => 'The host of your mail server.',
  67. ],
  68. 'mail_port' => [
  69. 'label' => 'Mail Port',
  70. 'type' => 'number',
  71. 'description' => 'The port of your mail server.',
  72. ],
  73. 'mail_username' => [
  74. 'label' => 'Mail Username',
  75. 'type' => 'string',
  76. 'description' => 'The username of your mail server.',
  77. ],
  78. 'mail_password' => [
  79. 'label' => 'Mail Password',
  80. 'type' => 'password',
  81. 'description' => 'The password of your mail server.',
  82. ],
  83. 'mail_encryption' => [
  84. 'label' => 'Mail Encryption',
  85. 'type' => 'select',
  86. 'options' => [
  87. 'null' => 'None',
  88. 'tls' => 'TLS',
  89. 'ssl' => 'SSL'
  90. ],
  91. 'description' => 'The encryption of your mail server.',
  92. ],
  93. 'mail_from_address' => [
  94. 'label' => 'Mail From Address',
  95. 'type' => 'string',
  96. 'description' => 'The from address of your mail server.',
  97. ],
  98. 'mail_from_name' => [
  99. 'label' => 'Mail From Name',
  100. 'type' => 'string',
  101. 'description' => 'The from name of your mail server.',
  102. ],
  103. 'mail_mailer' => [
  104. 'label' => 'Mail Mailer',
  105. 'type' => 'string',
  106. 'description' => 'The mailer of your mail server.',
  107. ],
  108. ];
  109. }
  110. }