Petro Gromovo
Petro Gromovo

Reputation: 2171

Why sending sms using vonage service I did not got any sms?

On laravel 11 site creating new user I send sms using vonage service and https://fajarwz.com/blog/send-sms-from-laravel-app-using-vonage/ plugin

I send notification as

$user->notify(new SendConfirmSmsToRegisteredUserNotification(user: $user, confirmCms: $confirmCms));

and Notification class :

<?php

namespace App\Notifications;

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\VonageMessage;

class SendConfirmSmsToRegisteredUserNotification extends Notification
{
    use Queueable;

    private string $siteName;
    /**
     * Create a new notification instance.
     */
    public function __construct(private User $user, private string $confirmCms)
    {
        \Log::info($confirmCms); // I SEE IN LOG FILE THIS MESSAGE
        $this->siteName = 'Site name';
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['vonage'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\VonageMessage
     */
    public function toVonage($notifiable): VonageMessage
    {
        \Log::info($this->confirmCms); // I DO NOT SEE IN LOG FILE THIS MESSAGE

        return (new VonageMessage)
            ->from($this->siteName)
            ->content('Confirm code ' .$this->confirmCms . '.  Enter it!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            //
        ];
    }
}

Method toVonage of thr class above is not even called. Not any errors in log file.

In .env file there are parameters VONAGE_KEY and VONAGE_SECRET.

I did not get any sms and in vonage dashdord in logs I did not find any records about my sms.

Is my Notification class invalid ? Or what can be the reason of the error ?

"laravel/framework": "^11.27.2",
"laravel/vonage-notification-channel": "^3.3"

Thanks in advance!

Upvotes: 0

Views: 22

Answers (0)

Related Questions