firebase-php: Click action on push notification not working

Describe the bug

I have installed this package on laravel 9 it works really awesome but the problem is when ever i send push notification and user click on it it does not go to the website, although i have added click_action in push notification option. please guide thanks

Installed packages

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "repositories": [
        {
            "type": "path",
            "url": "./nova"
        },
        {
            "type": "path",
            "url": "./nova-components/Notifications"
        }
    ],
    "require": {
        "php": "^8.1",
        "ext-ftp": "*",
        "appstract/laravel-options": "^5.3",
        "blade-ui-kit/blade-heroicons": "^1.3",
        "blade-ui-kit/blade-icons": "^1.3",
        "bnt/notifications": "*",
        "doctrine/dbal": "^3.4",
        "guzzlehttp/guzzle": "^7.2",
        "james-heinrich/getid3": "^1.9",
        "joshcam/mysqli-database-class": "^2.9",
        "kreait/firebase-php": "^7.1",
        "laravel/cashier": "^14.5",
        "laravel/framework": "^9.19",
        "laravel/nova": "*",
        "laravel/sanctum": "^3.0",
        "laravel/scout": "^9.5",
        "laravel/tinker": "^2.7",
        "laravel/ui": "^v3.4.6",
        "laravelista/comments": "dev-master",
        "league/flysystem-aws-s3-v3": "^3.2",
        "livewire/livewire": "^v2.10.7",
        "madcoda/php-youtube-api": "^1.2",
        "nicolab/php-ftp-client": "^2.0",
        "norkunas/onesignal-php-api": "^2.9",
        "pbmedia/laravel-ffmpeg": "^8.1",
        "phpgangsta/googleauthenticator": "dev-master",
        "pion/laravel-chunk-upload": "^1.5",
        "platformcommunity/bunnycdn-storage": "^0.2.0",
        "platformcommunity/flysystem-bunnycdn": "^3.0",
        "predis/predis": "^2.1",
        "spatie/nova-tags-field": "3.4.5"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.7",
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "pestphp/pest": "^1.21",
        "pestphp/pest-plugin-laravel": "^1.2",
        "phpunit/phpunit": "^9.5.10",
        "spatie/laravel-ignition": "^1.0"
    },
    "autoload": {
        "files": [
            "app/helpers.php"
        ],
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi",
            "@php artisan vendor:publish --force --tag=livewire:assets --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

PHP version and extensions

php 8.1

Steps to reproduce the issue.

# Insert the commands issued in the terminal if they are needed
# to reproduce the issue. Otherwise, delete this code block.
// Insert the PHP code to reproduce the issue. Please ensure that it is code that
// can be copy pasted to reproduce it.

Error message/Stack trace

click action on push notification not working

Additional information

thats all

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 24 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I am not entirely certain, but it seems that the web push notification is functioning properly. When I click on the notification, it opens up the browser.


        $messaging = app('firebase.messaging');
        $deviceToken = 'eKklqaQHo05yEOuxttdghK:1_GEQdCoPULkN1DG4h1Lc_pMVEiWuuufSG3JcyNcJ1oQWjqxiqTSR8mcL-EA';

        if($request->input('token'))
        {
            $deviceToken = $request->input('token');
        }
        $webPushConfig = WebPushConfig::fromArray([
            'notification' => [
                'title' => rand(1111,88888).' The Title',
                'body' => 'Check the movie you are waiting for',
                'image' => 'https://image.tmdb.org/t/p/w1280//raDj1xSVzBenwI87arenZY6eHmz.jpg',
                'icon' => 'https://image.tmdb.org/t/p/w150//raDj1xSVzBenwI87arenZY6eHmz.jpg',
                "click_action" => "/tv/95603/Kuruluş-Osman?q=Kuruluş-Osman",
                "actions" => array(
                    array(
                        "title" => "Like",
                        "action" => "https://aflam.vip/test",
                        "icon" => "icons/heart.png"
                    ),
                    array(
                        "title" => "Unsubscribe",
                        "action" => "unsubscribe",
                        "icon" => "icons/cross.png"
                    )
                ),

            ],
            'fcm_options' => [
                'link' => 'https://aflam.vip'
            ]
        ]);

        $data = [
            'first_key' => 'First Value',
            'second_key' => 'Second Value',
        ];


        $message = CloudMessage::fromArray([
            'token' => $deviceToken,
            //'topic' => 'all_devices',
            'webpush' => $webPushConfig,
        ])->withData($data);


        $messaging->send($message);

I’m happy that the library has helped you save time 🚀.

I can add a section to the Troubleshooting section, but please keep in mind that I’m just the unpaid maintainer of an unofficial library, I can’t anticipate every gotcha that’s missing even in the official documentation 😕.

I hope you can understand that’s why I have a problem with terms like “rectify” and “confirm that you’ve personally tested X” and sometimes react poorly to them - I do testing, but only on the server side.

@beshoo example works as expected. With how complex Firebase gets, this service is no exception, and seems to lead oneself into a maze. Thanks guys for the time invested.

Solved Use click_action as /


"notification": {
      "title": "The best movie ever",
      "body": "Check the movie you are waiting for",
       'image' => 'https://image.tmdb.org/t/p/w500//raDj1xSVzBenwI87arenZY6eHmz.jpg',
      "click_action" => "/"
}