Files
fotospiel-app/app/Mail/GiftVoucherIssued.php

59 lines
1.7 KiB
PHP

<?php
namespace App\Mail;
use App\Models\GiftVoucher;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\URL;
class GiftVoucherIssued extends Mailable
{
use Queueable, SerializesModels;
public function __construct(
public GiftVoucher $voucher,
public bool $forRecipient = false
) {}
public function envelope(): Envelope
{
$amount = number_format((float) $this->voucher->amount, 2);
return new Envelope(
subject: $this->forRecipient
? __('emails.gift_voucher.recipient.subject', ['amount' => $amount, 'currency' => $this->voucher->currency])
: __('emails.gift_voucher.purchaser.subject', ['amount' => $amount, 'currency' => $this->voucher->currency]),
);
}
public function content(): Content
{
$amount = number_format((float) $this->voucher->amount, 2);
$printUrl = URL::signedRoute('marketing.gift-vouchers.print', [
'locale' => app()->getLocale(),
'voucher' => $this->voucher->id,
'code' => $this->voucher->code,
]);
return new Content(
view: 'emails.gift-voucher',
with: [
'voucher' => $this->voucher,
'amount' => $amount,
'currency' => $this->voucher->currency,
'forRecipient' => $this->forRecipient,
'printUrl' => $printUrl,
],
);
}
public function attachments(): array
{
return [];
}
}