January 10, 2022 12:00 AM (GMT+8)
Requiredlaravel-notification-channels/fcm
Set FIREBASE_CREDENTIALS
=
Example
FIREBASE_CREDENTIALS=C:\\laragon\\www\\laravel-starter\\storage\\app\\public\\account\\firebase.json
In File
{
"type": "service_account",
"project_id": "",
"private_key_id": "",
"private_key": "-----BEGIN PRIVATE KEY-----\\n=\\n-----END PRIVATE KEY-----\\n",
"client_email": "..[.iam.gserviceaccount.com](<mailto:[email protected]>)",
"client_id": "",
"auth_uri": "[<https://accounts.google.com/o/oauth2/auth>](<https://accounts.google.com/o/oauth2/auth>)",
"token_uri": "[<https://oauth2.googleapis.com/token>](<https://oauth2.googleapis.com/token>)",
"auth_provider_x509_cert_url": "[<https://www.googleapis.com/oauth2/v1/certs>](<https://www.googleapis.com/oauth2/v1/certs>)",
"client_x509_cert_url": "[<https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-60bk3%40tm-fcm-95e8a.iam.gserviceaccount.com>](<https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-60bk3%40tm-fcm-95e8a.iam.gserviceaccount.com>)"
}
Documentation : https://laravel-notification-channels.com/fcm/#usage
Implements HasRoutesNotifications
Use Notifiable
and Fcmable
Add function routeNotificationForFcm()
Example
class User extends Authenticatable implements HasRoutesNotifications
{
use HasApiTokens, HasFactory, Notifiable, Fcmable;
/**
* {@inheritDoc}
*/
public function routeNotificationForFcm()
{
return $this->currentAccessToken();
}
}
class FcmController
{
public function send() {
/** @var \\App\\Models\\User $user */
$user = Auth::user();
$array = [
'title' => 'this title',
'body' => 'this body',
'data_type' => 'registered',
...
];
Fcm::create($user, $array);
}
}
Import class Fcm
Detail in Timedoor\\Tmd-Membership\\App\\Service\\Crm