ldc-gen-game-web/app/Notifications/Customer/HasWonDiscount.php

68 lines
1.9 KiB
PHP

<?php
namespace App\Notifications\Customer;
use App\Lib\Discount as LibDiscount;
use App\Mail\Won\DiscountWonMail;
use App\Models\Discount;
use App\Models\Settings;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Notifications\Notification;
class HasWonDiscount extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @param LibDiscount $discount The discount as set in Settings.
* @param \App\Models\Discount $discount_model The discount model created from MesBr.
* @param string $first_name The client first name.
* @return void
*/
public function __construct(
protected LibDiscount $discount,
protected Discount $discount_model,
protected string $first_name
) {
}
/**
* Get the notification's delivery channels.
*
* @param object $notifiable
* @return array<int, string>
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function via(object $notifiable): array
{
// phpcs:enable
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param object $notifiable
* @return \Illuminate\Contracts\Mail\Mailable
*/
public function toMail(object $notifiable): Mailable
{
/** @var \App\Models\Settings */
$settings = app(Settings::class);
/** @var \App\Models\Customer $notifiable */
return (new DiscountWonMail(
new Address(
$notifiable->email,
$this->first_name
),
$settings->name,
$this->discount,
$this->discount_model->link
));
}
}