Sending push notifications in Laravel with Firebase Cloud Messaging (FCM)
If you need to send push notifications from Laravel to your Android and iOS apps, you’ve come to the right place.
Sending push notifications in Laravel with Firebase Cloud Messaging (FCM)
If you need to send push notifications from Laravel to your Android and iOS apps, you’ve come to the right place.
First, we need to install a small and simple package in our Laravel project:
composer require garest/firebase-sender
Next, we need to publish the config file:
php artisan vendor:publish --tag=firebase-sender-config
Open the config/firebase-sender.phpconfiguration file and locate the service_accounts array.
This is where the data for accessing Firebase via Service Account is stored.
'service_accounts' => [
'###WRITE_YOUR_OWN_NAME_HERE###' => [
'project_id' => "###REPLACE_WITH_YOUR_PROJECT_ID###",
'private_key' => "###REPLACE_WITH_YOUR_PRIVATE_KEY###",
'client_email' => "###REPLACE_WITH_YOUR_CLIENT_EMAIL###"
],
]
The value ###WRITE_YOUR_OWN_NAME_HERE### is an arbitrary key (account name) that you will then use in your code.
The screenshot below shows how to get a Service Account from Firebase.

Service account
This completes the package configuration. Next, we can move on to sending push notifications.
Below is an example of sending a push notification to a specific user.
$firebaseSender = new FirebaseSender('SERVICE_ACCOUNT_NAME');
$firebaseSender->setDeviceToken("DEVICE_TOKEN");
$firebaseSender->setNotification(new NotificationPush(
title: "title",
body: 'body'
));
$firebaseSender->send();
You can also send push notifications on topics:
$firebaseSender = new FirebaseSender('SERVICE_ACCOUNT_NAME');
$firebaseSender->setTopic('TOPIC_NAME');
$firebaseSender->setNotification(new NotificationPush(
title: "title",
body: 'body'
));
$firebaseSender->send();
The setTopic method also supports the construction of complex AND and OR conditions.
$firebaseSender->setTopic(TopicCondition::make()
->topic('topicA')
->and()
->group(fn($group) => $group->topic('topicB')->or()->topic('topicC'))
);
Localization
Another interesting feature worth mentioning is sending localized push notifications, which use localization keys from your application.
For example, we have the following localization keys in our Android app:
<string name="title">Lorem ipsum</string>
<string name="body">Officia voluptate suscipit, nulla alias autem ipsa molestias id?</string>
To send notifications with these keys, we use the following code:
$firebaseSender = new FirebaseSender('SERVICE_ACCOUNT_NAME');
$firebaseSender->setDeviceToken("DEVICE_TOKEN");
$firebaseSender->setAndroid(new AndroidPush(
titleLocKey: 'title',
bodyLocKey: 'body'
));
$firebaseSender->setApns(new ApnsPush(
titleLocKey: 'title',
bodyLocKey: 'body'
));
$firebaseSender->send();
This package has many other useful features that you can explore on GitHub.
메타데이터
- post_id
- 801d39efec49
- slug
- sending-push-notifications-in-laravel-with-firebase-cloud-messaging-fcm-801d39efec49
- url
- https://medium.com/@garest/sending-push-notifications-in-laravel-with-firebase-cloud-messaging-fcm-801d39efec49
- canonical_url
- https://medium.com/@garest/sending-push-notifications-in-laravel-with-firebase-cloud-messaging-fcm-801d39efec49
- author_url
- https://medium.com/@garest
- status
- ok
- fetched_at
- 2026-06-11 05:11:55