title: Sending Firebase push notifications from Laravel
body: <p>I am writing an iOS application, using laravel for API and google firebase for push notifications. When I send a push notification using firebase cloud messaging, it comes to my device. When I send push notifications using laravel, it does not affect. Here is my script for sending push notifications from laravel:</p>
  
  <pre class="lang-php prettyprint-override"><code>function sendNotification(Request $request)
  {
      $friendToken = [];
      $usernames = $request-&gt;all()['friend_usernames'];
      $dialog_id = $request-&gt;all()['dialog_id'];
      foreach ($usernames as $username) {
          $friendToken[] = DB::table('users')-&gt;where('user_name', $username)
              -&gt;get()-&gt;pluck('device_token')[0];
      }
  
      $url = 'https://fcm.googleapis.com/fcm/send';
      foreach ($friendToken as $tok) {
          $fields = array(
              'to' =&gt; $tok,
              'data' =&gt; $message = array(
                  "message" =&gt; $request-&gt;all()['message'],
                  "dialog_id" =&gt; $dialog_id
              )
          );
          $headers = array(
              'Authorization: key=*mykey*',
              'Content-type: Application/json'
          );
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
          curl_exec($ch);
          curl_close($ch);
      }
  
      $res = ['error' =&gt; null, 'result' =&gt; "friends invited"];
  
      return $res;
  }
  </code></pre>
  
  <p>It returns a successful result, but notification not sent to iOS devices.</p>
  
  <p>PS: It works successfully on Android devices.</p>