繁体   English   中英

Laravel Nexmo SMS通知未发送

[英]Laravel Nexmo SMS Notifications not sending

我正在尝试使用Laravel中的Nexmo发送SMS通知,我一直在遵循官方文档指南

由于某种原因,我的通知无法发送,但是我完全没有收到任何错误。

我已经设置了Notification类:

<?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中,我以update方法发送实际的SMS通知:

 /**
 * 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))
}

当我更新记录时,它可以完全保存而没有任何错误,但是我没有收到短信。 有人知道我在做什么错吗?

谢谢

编辑

通知正在存储在数据库中,但数据为空:

在此处输入图片说明

问题是在Notification类的via方法中,我必须将nexmo设置为通道:

     /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['nexmo'];
    }

它将默认为数据库,因此为什么我要在数据库中获取记录。 现在,它可以发送短信了。

如果要将通知存储在数据库中以及通过nexmo发送短信,则可以返回两个通道:

return ['nexmo', 'database'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM