2016-11-02 5 views
1

Ich benutze diese Bibliothek: https://github.com/davibennun/laravel-push-notification zum Senden von Push-Benachrichtigungen. Ich habe den Beispielcode benutzt und die Push-Nachrichten an meinem iPhone funktionieren.Laravel Push-Benachrichtigungen

Nur jetzt möchte ich 1 Nachricht an mehrere Geräte senden. Die docs sagen, dass ich verwenden müssen:

$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(); 
    } 

Aber ich will eine foreach-Schleife aus meiner Datenbank auf dem devicecollection. Wie mache ich das mit Laravel? Danke vielmals!

+0

Sie meinen, eine Datenbankspalte mit correspondig Geräte mit? –

+0

Ich meine ich habe eine for-Schleife Beispiel: foreach ($ Geräte als $ Gerät) { $ Gerät-> Token; } Ich möchte, dass Tokens in der DeviceCollection-Array –

+0

Mai bitte teilen Sie mehr Code dafür, Ich habe auch Probleme mit der Implementierung dieser Bibliothek. Ich benutze Laravel 5.5.14 – Noitidart

Antwort

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

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

bereits fest, heute war nicht scharf haha ​​