36 lines
819 B
PHP
36 lines
819 B
PHP
<?php
|
|
|
|
namespace App\Notifications\Channels;
|
|
|
|
use App\Notifications\Messages\SmsMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use Overtrue\EasySms\EasySms;
|
|
|
|
class SmsChannel
|
|
{
|
|
/**
|
|
* @param \Overtrue\EasySms\EasySms $easySms
|
|
*/
|
|
public function __construct(
|
|
protected EasySms $easySms
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param mixed $notifiable
|
|
* @param \Illuminate\Notifications\Notification $notification
|
|
* @return void
|
|
*/
|
|
public function send($notifiable, Notification $notification): void
|
|
{
|
|
$message = $notification->toSms($notifiable);
|
|
$phone = $notifiable->routeNotificationFor('sms', $notification);
|
|
|
|
if (! $phone && ! $message instanceof SmsMessage) {
|
|
return;
|
|
}
|
|
|
|
$this->easySms->send($phone, $message);
|
|
}
|
|
}
|