File: //home/armgroup/libs/app/Notifications/DiscountCode.php
<?php
namespace App\Notifications;
use App\Channels\SMSChannel;
use App\Enums\NotificationType;
use App\Models\Discount;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class DiscountCode extends Notification implements ShouldQueue
{
use Queueable;
public $discount;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Discount $discount)
{
$this->discount = $discount;
}
public function viaQueues()
{
return [
'mail' => 'mail-queue',
SMSChannel::class => 'sms-queue',
];
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
switch ($this->discount->notification_type) {
case NotificationType::EMAIL:
return ['mail'];
case NotificationType::SMS:
return [SMSChannel::class];
default:
return ['mail', SMSChannel::class];
}
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$mail = (new MailMessage)->subject($this->discount->title);
foreach (explode("\n", $this->discount->message) as $line) {
$mail = $mail->line($line);
}
$mail = $mail->action(settings('title'), route('index'));
return $mail;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
public function toSMS($notifiable)
{
return [
];
}
}