PHP code example of foziluff / firebase

1. Go to this page and download the library: Download foziluff/firebase library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

foziluff / firebase example snippets


use Foziluff\Firebase\Facades\FirebasePush;

// Standard notification
FirebasePush::toToken($token)
    ->withTitle('Hello World')
    ->withBody('This is a test notification.')
    ->send();

// With custom data payload, sound, and image
FirebasePush::toToken($token)
    ->withTitle('Order Shipped')
    ->withBody('Your order #1234 is on the way!')
    ->withData(['order_id' => 1234])
    ->withSound('default')
    ->withImage('https://example.com/images/promo.jpg')
    ->send();

use Foziluff\Firebase\Facades\FirebasePush;

FirebasePush::toTopic('news') // or '/topics/news'
    ->withTitle('Breaking News')
    ->withBody('Laravel is awesome!')
    ->withData(['article_id' => 42])
    ->send();

FirebasePush::toToken($token)
    ->withData(['action' => 'sync_data'])
    ->send();

FirebasePush::sendRaw([
    'token' => $token,
    'notification' => [
        'title' => 'Custom Push'
    ],
    'android' => [
        'priority' => 'high'
    ]
]);

$response = FirebasePush::toToken($token)
    ->withTitle('Title')
    ->withBody('Body')
    ->send();

if (isset($response['error'])) {
    // The device token is invalid, unregistered, or malformed.
    // E.g. $response['error']['details'][0]['errorCode'] === 'UNREGISTERED'
    $user->update(['fcm_token' => null]);
}