Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

How to add badge on push notification using brozot/Laravel-FCM #205

@pramukhreddy

Description

@pramukhreddy

@brozot ----> Please Help

How to add badge on push notification using brozot/Laravel-FCM ?

I'm sending and receiving push notifications correctly on iOS devices, but I would like to know how can I send badge information with the notification builder?

I tried this code but it is not working (see error below):

`$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(43200);

        $notificationBuilder = new PayloadNotificationBuilder();
        
        $notificationBuilder->setBody($payload['notificationmessage'])
                                ->setImage($payload['imageurl'])
                                ->setBadge($payload['badgecount']);
        
        $dataBuilder = new PayloadDataBuilder();
        $dataBuilder->addData(['device_data' => $payload]);

        $option = $optionBuilder->build();
        $notification = $notificationBuilder->build();
        $data = $dataBuilder->build();
        
        $downstreamResponse = FCM::sendTo($value->device_token, $option, $notification,  @$data);

But it is throwing following error

[2020-11-02 04:49:28] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function setBadge() on string in /var/www/html/app/Http/Controllers/api/v1/NotificationsController.php:221

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions