laravel-notification-channels / aws-sns

AWS SNS notification channel for Laravel
https://laravel-notification-channels.com/aws-sns
MIT License
50 stars 9 forks source link

routeNotificationForSns not working for different field name #19

Closed Zubair-Iftikhar closed 2 years ago

Zubair-Iftikhar commented 3 years ago

routeNotificationForSns is not working.. in User Model.. if then db field is phone then it's working fine.. but what if field name other?

    public function routeNotificationForSns($notification)
    {
        return $notification->mobileNumber;
    }
claudsonm commented 3 years ago

I believe you are using the wrong way. The Usage section addresses this.

You have to put the routeNotificationForSns() in the model you are trying to send the notification to. If its a User, get the phone number of the user, not the mobile number of the notification. There is no property mobileNumber in the notification object.

I think it should be:

<?php

use Illuminate\Notifications\Notifiable;

class SomeModel {
    use Notifiable;

    public function routeNotificationForSns($notification)
    {
        return $this->mobileNumber;
    }
}
Zubair-Iftikhar commented 3 years ago

I believe you are using the wrong way. The Usage section addresses this.

You have to put the routeNotificationForSns() in the model you are trying to send the notification to. If its a User, get the phone number of the user, not the mobile number of the notification. There is no property mobileNumber in the notification object.

I think it should be:

<?php

use Illuminate\Notifications\Notifiable;

class SomeModel {
    use Notifiable;

    public function routeNotificationForSns($notification)
    {
        return $this->mobileNumber;
    }
}

already do in User model.. but not working

claudsonm commented 3 years ago

Yes, its in the user model, but the code you posted is wrong. It's not return $notification->mobileNumber;, it should be return $this->mobileNumber;

If you already fixed this, and is not working yet, this issue here can help you debug what's happening: https://github.com/laravel-notification-channels/aws-sns/issues/9