File: /home/armgroup/libs/app/Channels/SMSChannel.php
<?php
namespace App\Channels;
use App\FarazSms;
use Illuminate\Notifications\Notification;
class SMSChannel
{
public function send($notifiable, Notification $notification)
{
$mobile = $notifiable->routeNotificationFor(SMSChannel::class, $notification) ?: $notifiable->mobile;
$data = $notification->toSMS($notifiable);
if (! app()->isProduction()) {
info($mobile, $data);
return;
}
if ($this->canSendMessage($data)) {
try{
send_sms($mobile,$data,$data['pattern']);
\Log::alert('send sms with pattern.', ['pattern' => $data['pattern']]);
} catch (\Exception $exception) {
\Log::warning('not send sms with pattern.', ['pattern' => $data['pattern']]);
info($exception->getMessage());
}
}
}
// private function canSendMessage($data): bool
// {
// return is_array($data) && count($data) >= 2 && array_key_exists('pattern', $data);
// }
private function canSendMessage($data): bool
{
return is_array($data) && count($data) == 4 && array_key_exists('var1', $data) && array_key_exists('var2', $data) && array_key_exists('var3', $data) && array_key_exists('pattern', $data);
}
}