我正在尝试在 Laravel 中使用 Nexmo 发送短信通知,我一直在关注官方文档指南。
由于某种原因,我的通知没有发送,但我根本没有收到任何错误。
我已经设置了我的通知类:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Message\NexmoMessage;
class bookingAdded extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the Nexmo / SMS representation of the notification.
*
* @param mixed $notifiable
* @return NexmoMessage
*/
public function toNexmo($notifiable)
{
return (new NexmoMessage)
->content('Your SMS message content');
}
}
在我的Booking
模型中,我添加了routeNotificationForNexmo()
自定义通知发送到的电话号码的方法:
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Booking extends Model
{
use Notifiable;
/**
* Route notifications for the Nexmo channel.
*
* @return string
*/
public function routeNotificationForNexmo()
{
$intl_number = preg_replace('/^07/','447', $this->customer_phone);
return $intl_number;
}
}
在我的方法BookingController
中,我正在发送实际的 SMS 通知update
:
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(BookingRequest $request, $id)
{
$booking = Booking::find($id);
$booking->notify(new bookingAdded($booking))
}
当我更新一条记录时,它完全没有任何错误地保存,但我没有收到短信。有人知道我在这里做错了什么吗?
谢谢
编辑
通知存储在数据库中,但数据为空: