Reputation: 467
Hi I am making laravel SMS Notification by using Nexmo API.
I have integrated nexmo as per given laravel documentation and as well as given in github.
My below code is working fine.
Nexmo::message()->send([
'to' => 'xxxxxxx',
'from' => 'xxxxxxx',
'text' => 'Using the facade to send a message.'
]);
the above code is sending the SMS.
I need this to integrate as a Notification. but unfortunately return ['nexmo']
did not work. It did not hit to toNexmo($notifiable)
method in the notification.
Can anyone help me.
Thanks
Upvotes: 3
Views: 1115
Reputation: 11656
To
phone number on your User model: public function routeNotificationForNexmo($notification)
{
return $this->phone_number;
}
Upvotes: 1
Reputation: 431
There are two ways to send notifications via Nexmo - using the built in Notifications package and using the Nexmo client. You've implemented it using the client, but it looks as though you want to use the notifications package instead so that it calls toNexmo
.
To send a notification via Laravel, dispatch it like this:
Notification::send($yourUser, new SomethingNotification());
The SomethingNotification
definition looks like the following:
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\NexmoMessage;
class SomethingNotification extends Notification
{
public function via($notifiable)
{
return ['nexmo'];
}
public function toNexmo($notifiable)
{
return (new NexmoMessage)
->content('Some content');
}
}
Upvotes: 3