PHP code example of alfa6661 / laravel-firebase

1. Go to this page and download the library: Download alfa6661/laravel-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/ */

    

alfa6661 / laravel-firebase example snippets


// config/app.php
'providers' => [
    ...
    Alfa6661\Firebase\FirebaseServiceProvider::class,
],

// config/services.php
...
'firebase' => [
    'api_key' => env('FIREBASE_API_KEY'),
],
...

public function routeNotificationForFirebase()
{
    return ["DEVICE_TOKEN", "DEVICE_TOKEN"];
}
 php
use Alfa6661\Firebase\FirebaseChannel;
use Alfa6661\Firebase\FirebaseMessage;
use Illuminate\Notifications\Notification;

class CreditWasCreated extends Notification
{
    public function via($notifiable)
    {
        return [FirebaseChannel::class];
    }

    public function toFirebase($notifiable)
    {
        return FirebaseMessage::create()
            ->title('Title')
            ->body('Push notification body')
            ->data(['id' => $notifiable->id]);
    }
}