-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User with multiple devices #119
Comments
The setup should be pretty easy once we know that the Apn Notification Channel can accept an array of recipients (https://github.com/Edujugon/PushNotification/blob/master/src/Apn.php#L289). Just make sure your public function routeNotificationForApn()
{
// Simply return an array of the push tokens (multiple recipients).
$tokens = $this->devices()->get()->map(function ($device) {
$device->ios_push_token;
});
return $tokens->toArray();
} |
Okay, yeah it does have a token it's called something different but believe that will still work. This goes in the user model correct? |
@icemancast Yes. The value that you return is the recipient of the notification, or if you return an array, recipients. It's given that your User model has a public function devices()
{
return $this->hasMany(Device::class);
} |
How would you then get the feedback request if using this so I can unregister devices? |
Just delete the device row from the database? |
yes the feedback() method on a push gives back the failed tokens so I soft delete them from the database. I guess what I am trying to get to is mass notify however I can't send the badge(1) per user when i mass send the tokens through a push. I don't think i should iterate through each user and then grab their devices to send the unread badge number to. |
You can iterate through all users and send a notification, but for this you should use a job service (e.g redis). |
Okay @ExpDev07 and there should not be a rate limit for apple or android when doing this? I already have notifications working except for this part of the badge. I tried to do through laravel notification channel but didn't work that way and will likely refactor later. |
Using the notification channel how would i handle if a user has multiple devices? Currently I have a users table and a devices table that's a one to many. The notification setup shows:
/**
*/
public function routeNotificationForApn()
{
return $this->ios_push_token;
}
Which I assume would go in the users model. But I don't have a token for users I have a devices table that holds a users device. Any one user could have an iphone, ipad or any other device. Currently I pull all devices and send that list for a push which is working but i can't do stuff for instance of counting the users unread messages to badge as the list is all devices in the database. Does that make sense? Should i be iterating over the users and then sending their devices only? that doesn't seem like I should but just wondering.
The text was updated successfully, but these errors were encountered: