41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\Poll;
|
|
use App\Models\User;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
/**
|
|
* The voter's poll receipt code. Deliberately not ShouldQueue: sent right away so
|
|
* the code is never stored next to the address (jobs / failed_jobs tables).
|
|
*/
|
|
class PollReceiptMail extends Mailable
|
|
{
|
|
public string $mailLocale;
|
|
public string $pollTitle;
|
|
public ?string $verifyUrl;
|
|
|
|
public function __construct(public Poll $poll, public User $user, public string $receiptCode)
|
|
{
|
|
$this->mailLocale = $user->lang_preference ?: config('app.fallback_locale');
|
|
|
|
$translations = $poll->post?->translations ?? collect();
|
|
$this->pollTitle = ($translations->firstWhere('locale', $this->mailLocale) ?? $translations->first())?->title ?? '';
|
|
|
|
// The verification page is added in a later step
|
|
$this->verifyUrl = Route::has('polls.verify') ? route('polls.verify', $poll) : null;
|
|
}
|
|
|
|
public function build()
|
|
{
|
|
app()->setLocale($this->mailLocale);
|
|
|
|
return $this
|
|
->from(timebank_config('mail.support.email'), timebank_config('mail.support.name'))
|
|
->subject(__('Your poll receipt'))
|
|
->view('emails.polls.receipt');
|
|
}
|
|
}
|