Download the PHP package ideagen-damstra/push-notification without Composer
On this page you can find all versions of the php package ideagen-damstra/push-notification. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ideagen-damstra/push-notification
More information about ideagen-damstra/push-notification
Files in ideagen-damstra/push-notification
Package push-notification
Short Description Laravel Package to send push notifications to Android and IOS devices. (GCM,FCM,APN)
License MIT
Informations about the package push-notification
PushNotification Package
This is an easy to use package to send push notification.
Push Service Providers Available:
- GCM
- FCM
- FCMV1
- APN
Installation
Laravel version below 5.8
type in console:
Laravel 5.8/6 and higher
type in console:
The package will automatically register its service provider.
Publish the package's configuration file to the application's own config directory
Go to laravel facade sample directly.
Configuration
After publishing the configuration, you can find the Push service config in config/pushnotification.php
The default configuration parameters for GCM and FCM are :
- priority => normal
- dry_run => false
- apiKey => Your ApiKey
You can dynamically update those values or adding new ones calling the method setConfig like so:
The default configuration parameters for FCMV1 are :
You can dynamically update those values or adding new ones calling the method setConfig like so:
To generate a credentials json file for your service account:
- In the Firebase console, open Settings > Service Accounts.
- Click Generate New Private Key, then confirm by clicking Generate Key.
- Securely store the JSON file containing the key.
The default configuration parameters for APN are:
(Make sure to set dry_run
to true
if you're using development *.pem certificate, and false
for production)
Also you can update those values and add more dynamically
Even you may update the url of the Push Service dynamically like follows:
Not update the url unless it's really necessary.
You can specify the number of client-side attempts to APN before giving
up. The default amount is 3 attempts. You can override this value by
specifying connection_attempts
in setConfig()
assoc-array. Keep in
mind the default number of requested attempts is 3.
If you prefer to retry indefinitely, set connection_attempts
to zero.
$push->setConfig([
'passPhrase' => 'NewPass',
'custom' => 'MycustomValue',
'connection_attempts' => 0,
'dry_run' => true
]);
Usage
By default it will use GCM as Push Service provider.
For APN Service:
For FCM Service:
For FCMV1 Service:
Now you may use any method that you need. Please see the API List.
API List
Only for Gcm and Fcm
Only for Fcm
Only for Fcmv1
Go to Usage samples directly.
setService
setService
method sets the push service to be used, which you pass the name through parameter as a string.
Syntax
setMessage
setMessage
method sets the message parameters, which you pass the values through parameter as an array.
Syntax
setApiKey
Only for gcm and fcm
setApiKey
method sets the API Key of your App, which you pass the key through parameter as a string.
Syntax
setProjectId
Only for fcmv1
setProjectId
method sets the Project ID of your App as a string.
Syntax
setJsonFile
Only for fcmv1
setJsonFile
method sets the path of credentials json file of your App.
Syntax
setDevicesToken
setDevicesToken
method sets the devices' tokens, which you pass the token through parameter as array or string if it was only one.
Syntax
send
send
method sends the notification.
Syntax
getFeedback
getFeedback
method gets the notification response, which you may use it chaining it to send
method or call it whenever after sending a notification.
Syntax
getUnregisteredDeviceTokens
getUnregisteredDeviceTokens
method gets the devices' tokens that couldn't receive the notification because they aren't registered to the Push service provider.
You may use it chaining it to send
method or call it whenever after sending a notification.
Syntax
setConfig
setConfig
method sets the Push service configuration, which you pass the name through parameter as an array.
Syntax
setUrl
setUrl
method sets the Push service url, which you pass the name through parameter as a string.
Syntax
Not update the url unless it's really necessary.
sendByTopic
Only for fcm
sendBytopic
method sends a message by topic. It also accepts the topic condition. more details here
If isCondition is true, $topic will be treated as an expression
Syntax
Usage samples
You can chain the methods.
GCM sample:
APN sample:
or do it separately
If you want send the notification to only 1 device, you may pass the value as string.
Send the Notification
Method send() can be also chained to the above methods.
Send the Notification by Topic (FCM only)
or with a condition:
Understanding Gcm and Fcm Message Payload
Notification Message
Add a notification
key when setting the message in setMessage
method. like follows:
You may add some extra payload adding a data
key when setting the message in setMessage
method.
Data Message
By default, this package sends the notification as Data Message. So no need to add a data
key.
The above example is like you were sending the following:
For more details, have a look at gcm/fcm notification paypload support and the concept options
Getting the Notification Response
If you want to get the push service response, you can call the method getFeedback
:
Or again, chain it to the above methods:
It will return an object with the response.
APN Server Feedback and package Feedback
Any time you send a notification, it will check if APN server has any feedback for your certificate. If so, the responses are merged to our feedback like below:
Get Unregistered Devices tokens
After sending a notification, you may retrieve the list of unregistered tokens
This method returns an array of unregistered tokens from the Push service provider. If there isn't any unregistered token, it will return an empty array.
Laravel Alias Facade
After register the Alias Facade for this Package, you can use it like follows:
It would return the Push Feedback of the Notification sent.
Notification channels
Formatting Push Notifications
If a notification supports being sent as an push message, you should define toApn
and/or toFcm
/toGcm
methods on the notification class. This method will receive a $notifiable
entity and should return a Edujugon\PushNotification\Messages\PushMessage
instance:
Customizing The Title and Body
Customizing The Notification Sound
Customizing The Badge Number
Passing Service Config
Add it to the notification channels
Don't forget the use statement at the top of the class
Routing Push Notifications
Just define routeNotificationForApn
and/or routeNotificationForFcm
/routeNotificationForGcm
methods on the entity
All versions of push-notification with dependencies
guzzlehttp/guzzle Version ^6.3 || ^7.0.1
illuminate/support Version ~5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
illuminate/notifications Version ~5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
google/apiclient Version ^2.15