dqpc1845 2017-06-21 19:36
浏览 45
已采纳

Laravel Nexmo SMS Notifications未发送

I am trying to send SMS notifications using Nexmo in Laravel, I have been following the official documentation guide.

For some reason my notifications do not send, but I don't get any errors at all.

I've set up my Notification class:

<?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');
    }

}

In my Booking model I have added the routeNotificationForNexmo() method to customize the phone number the notification is delivered to:

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;
    }

}

In my BookingController I am sending the actual SMS notification in my update method:

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

When I update a record it saves without any errors at all, but I don't receive the sms. Anyone know what I'm doing wrong here?

Thanks

EDIT

The notifications are being stored in the database but the data is empty:

enter image description here

  • 写回答

1条回答 默认 最新

  • doudouwd2017 2017-06-21 20:15
    关注

    The issue was that in the via method in the Notification class I had to set nexmo as the channel:

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

    It would default to database, hence why I was getting records in my db. Now it sends the sms fine.

    If you want to store the notifications in the database as well as send the sms through nexmo you can just return both channels:

    return ['nexmo', 'database'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。