Skip to content

A simple backend server in laravel to send push notifications to mobile devices through FCM

Notifications You must be signed in to change notification settings

bul-ikana/pushtest-laravel

Repository files navigation

Laravel push - backend

A simple example of using brozot/Laravel-FCM with Laravel to send push notifications to mobile devices through FCM.

About

This project sends a push notification to mobile devices upon request. Once installed, a GETrequest to http://[project root]/api/push?animal=[animal]&token=[FCM token] will send a push notification to the device whose FCM token was provided.

A different notification will be sent depending on the animal parameter. The available animals are:

  • cat
  • cow
  • dog
  • duck
  • pig

Any other animal will send a default notification.

It is easier to test, and intended to be used with pushtest-android.

How it works?

A call to the controller will dispatch a SendPushNotification job to be sent to the queue and processed eventually by the queue worker. This speeds up web requests as sending of notifications is processed asynchronously. If you want to send the notification immediately after processing the request, check the simple-notification tag of this repo, which uses no queues. The notification part defines how the notification will show on the user notifacation center. The data part sets extra data than will be passed to the screen defined in the click_action value of the notification.

Running the project

  • Make sure you have Laravel ready development or staging environment. Homestead is a great option, but not the only one
  • Create a Firebase project in the Firebase console. You will need a server key and a sender ID
  • Clone the repo
  • Install dependencies running composer install
  • Configure your environment in the .env file. Don't forget to add your Firebase data. If you want to change the queue driver, this is the place
  • Run migrations by running php artisan migrate
  • Run the queue worker in background by running php artisan queue:work &. Keep in mind jobs will only be processed while this process is running, so you may want to keep it running using Supervisor or some tool like that
  • Done. Everything is ready to start accepting request and sending notifications to devices

Questions?

Please feel free to raise an issue in our issue page.

About

A simple backend server in laravel to send push notifications to mobile devices through FCM

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages