"{"multicast_id":2590279481594016535, "success":0, "failure":1, "canonical_ids":0, "results":[{"error":"InvalidRegistration"}]}"
this Error i am getting, below is the code.
$deviceToken = Str::random(60);
// Store the device token in the user's record
$user->forceFill([
'device_token' => $deviceToken,
])->save();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: key=SERVER_KEY',
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = array(
"to" => $token,
"notification" => array(
"title" => 'Login successful',
"body" => 'You have successfully logged in.',
"sound" => 'default'
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
This is the correct way to pass the token.