0

i am trying Edujugon Push Notification laravel; all configuration be correct. my push notification code is

$push = new PushNotification('fcm');

    $push->setMessage([
    'notification' => [
            'title'=>'This is the title',
            'body'=>'This is the message',
            'sound' => 'default'
            ],
    'data' => [
            'extraPayLoad1' => 'value1',
            'extraPayLoad2' => 'value2'
            ]
    ])        
    ->setApiKey('AAAAv7w78uY:APA91bF73GY1AcZvBh84K2matRxFwWB0VQysqlDzsLBtrmVRbRN0e6T2Lxasiv-sNfWaNQwqgltTaiaL0rZVC5TKzwfZRgrxb30B4jkl2bzJ9DViZsbGVdQMNOJ78FtOfwcUCgvUj_XC7jLdargjnfKQAD0ecbWMlA')
    ->setDevicesToken('fj6Sx3zYjhM:APA91bE3cas4LPX-T9jJ-7YgKrMIYOiD5Brjf9AgqvCUsSN7OygZEX3qhQ1F4RxCZfsvSCHNV9gq15NL26k62KBuWqpX4G9nrSQHT3ddabCTRwinqbmpt53gtdCgakaW5LvSxA1t1-iiZS8at8pW7W9o5Gyv2mBSEw');
    $push = $push->send();
Dhruv Yadav
  • 41
  • 1
  • 7

3 Answers3

0

Please refer https://packagist.org/packages/edujugon/push-notification

$push->setMessage([
    'notification' => [
            'title'=>'This is the title',
            'body'=>'This is the message',
            'sound' => 'default'
            ],
    'data' => [
            'extraPayLoad1' => 'value1',
            'extraPayLoad2' => 'value2'
            ]
    ])
    ->setApiKey('Server-API-Key')
    ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...]);
Arya
  • 504
  • 2
  • 8
  • 31
0

used this package LARAVEL-FCM EASY TO USED

Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
0

I have also integrated push notification in laravel using below code, hope it helps you :

function sendPushNotification($fcm_token, $title, $message, $id="") {  
        $push_notification_key = Config::get('settings.PUSH_NOTIFICATION_KEY');    
        $url = "https://fcm.googleapis.com/fcm/send";            
        $header = array("authorization: key=" . $push_notification_key . "",
            "content-type: application/json"
        );    

        $postdata = '{
            "to" : "' . $fcm_token . '",
                "notification" : {
                    "title":"' . $title . '",
                    "text" : "' . $message . '"
                },
            "data" : {
                "id" : "'.$id.'",
                "title":"' . $title . '",
                "description" : "' . $message . '",
                "text" : "' . $message . '",
                "is_read": 0
              }
        }';

        $ch = curl_init();
        $timeout = 120;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

        // Get URL content
        $result = curl_exec($ch);    
        // close handle to release resources
        curl_close($ch);

        return $result;
    }
Manoj Patel
  • 329
  • 3
  • 11
  • Welcome to Stack Overflow! While this code may answer the question, it is better to include some context, explaining how it works and when to use it. Code-only answers tend to be less useful in the long run. See [How do I write a good answer? ](https://stackoverflow.com/help/how-to-answer) for some more info. – Mark Ormesher Jan 03 '19 at 07:54