ECOMMERCE/app/Notifications/Auth/RequestOtp.php

76 lines
1.8 KiB
PHP

<?php
namespace App\Notifications\Auth;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Notifications\WaNotification;
use App\Notifications\WahitsChannel;
use App\Notifications\WahaChannel;
use App\Notifications\WagaChannel;
class RequestOtp extends WaNotification
{
use Queueable;
var $otp;
var $prefer;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($otp, $prefer = "wa")
{
$this->otp = $otp;
$this->prefer = $prefer;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return $this->prefer == "wa" ? [WahitsChannel::class] : ["mail"];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Your One-Time Password (OTP)')
->greeting('Hi '.$notifiable->name)
->line('Your One-Time Password (OTP) is:')
->line("**{$this->otp}**")
->line('This code is valid for 10 minutes.')
->line('If you did not request this, please ignore this email.')
->salutation('Regards, Asia Golf');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toWa($notifiable)
{
$otp = $this->otp;
return [
"text" => "$otp ini adalah kode OTP untuk anda login.
JANGAN berikan kode OTP ke siapapun!"
];
}
}