1
votes

I'm using this library: https://github.com/davibennun/laravel-push-notification for sending push notifications. I used the example code and the push messages to my iPhone are working.

Only now I want to send 1 message to multiple devices. The docs say that I need to use:

$devices = PushNotification::DeviceCollection(array(
        PushNotification::Device('token', array('badge' => 5)),
        PushNotification::Device('token1', array('badge' => 1)),
        PushNotification::Device('token2')
    ));
    $message = PushNotification::Message('Message Text',array(
        'badge' => 1,
        'sound' => 'example.aiff',

        'actionLocKey' => 'Action button title!',
        'locKey' => 'localized key',
        'locArgs' => array(
            'localized args',
            'localized args',
        ),
        'launchImage' => 'image.jpg',

        'custom' => array('custom data' => array(
            'we' => 'want', 'send to app'
        ))
    ));

    $collection = PushNotification::app('appNameIOS')
        ->to($devices)
        ->send($message);
// get response for each device push
    foreach ($collection->pushManager as $push) {
        $response = $push->getAdapter()->getResponse();
    }

But I want a foreach loop from my database on the devicecollection. How do I do that with laravel? Many thanks!

1
You mean having a database column with correspondig devices?Jan Willem
I mean I have a for loop example: foreach($devices as $device){ $device->token; } I want that tokens in the DeviceCollection arrayDw1-nl
May you please share more code for this, I am also struggling with implementing this lib. I am using Laravel 5.5.14Noitidart

1 Answers

1
votes
foreach($usersApple as $userApple){
                echo $userApple->reg_id . '<br>';
                $deviceslist[] = PushNotification::Device($userApple->reg_id);
            }

            $devices = PushNotification::DeviceCollection($deviceslist);

Already fixed, was not sharp today haha