laravel-fcm-notification icon indicating copy to clipboard operation
laravel-fcm-notification copied to clipboard

Where do we pass in the device token of the user to whom we are sending the push?

Open Gameonn opened this issue 4 years ago • 1 comments

I am using toFCM function, but in that there is no where mentioned where to specify the registration_id or device_token to send push.

public function toFcm($notifiable) 
{
    $message = new FcmMessage();
    $message->content([
        'title'        => 'Test Push', 
        'body'         => 'Sample push notification', 
    ])->priority(FcmMessage::PRIORITY_HIGH);
    
    return $message;
}

Gameonn avatar Aug 23 '20 16:08 Gameonn

Place this code in the model

/**
 * Route notifications for the FCM channel.
 *
 * @param  \Illuminate\Notifications\Notification  $notification
 * @return string
 */
public function routeNotificationForFcm($notification)
{
    return $this->device_token;
}

you need to make use of laravel notification feature call on model

php artisan make:notification PushNotification

and Add the method public function toFcm($notifiable) to your notification, and return an instance of FcmMessage:

then use it

$user->notify(new PushNotification($parm));

Aksoom-Hussain avatar May 16 '21 02:05 Aksoom-Hussain