68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Mail\Customer;
|
|
|
|
use App\Mail\Concerns\RequiresDbTemplate;
|
|
use App\Models\Setting;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class Welcome extends Mailable
|
|
{
|
|
use Queueable, SerializesModels, RequiresDbTemplate;
|
|
|
|
public function __construct(public array $data) {}
|
|
|
|
public function envelope(): Envelope
|
|
{
|
|
return new Envelope(
|
|
subject: $this->renderFromTemplate('customer_welcome', $this->vars())['subject'],
|
|
);
|
|
}
|
|
|
|
public function content(): Content
|
|
{
|
|
return new Content(
|
|
htmlString: $this->renderFromTemplate('customer_welcome', $this->vars())['html'],
|
|
);
|
|
}
|
|
|
|
public function attachments(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
private function vars(): array
|
|
{
|
|
$data = $this->payload();
|
|
|
|
return [
|
|
'app_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
|
|
'full_name' => $data['fullname'] ?? 'Quý khách',
|
|
'login_url' => $data['login_url'] ?? rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/dang-nhap',
|
|
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
|
|
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
|
|
];
|
|
}
|
|
|
|
private function payload(): array
|
|
{
|
|
try {
|
|
$setting = Setting::where('key', 'setting')->first();
|
|
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
|
|
} catch (\Throwable) {
|
|
$settingValue = [];
|
|
}
|
|
|
|
return array_merge([
|
|
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
|
|
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
|
|
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
|
|
'login_url' => rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/dang-nhap',
|
|
], $this->data);
|
|
}
|
|
}
|