laravel-notification-channels / fcm

Firebase Cloud Messaging (FCM) notifications channel for Laravel
https://laravel-notification-channels.com/
MIT License
472 stars 121 forks source link

My brain is not braining reading docs for multiple app or usingClient #190

Closed masterbater closed 5 months ago

masterbater commented 5 months ago

With the underlying Firebase we can set another project using config/firebase.php just add another entry like another-app

use Kreait\Laravel\Firebase\Facades\Firebase;

// Return an instance of the Auth component for the default Firebase project
$defaultAuth = Firebase::auth();
// Return an instance of the Auth component for a specific Firebase project
$appAuth = Firebase::project('app')->auth();
$anotherAppAuth = Firebase::project('another-app')->auth();

In this project, how can call underlying project like another-app, is the usingClient is the use case for this, but I dont understand this line $client = app(\Kreait\Firebase\Contract\Messaging::class);

public function toFcm(mixed $notifiable): FcmMessage
{
    $client = app(\Kreait\Firebase\Contract\Messaging::class);

    return FcmMessage::create()->usingClient($client);
}
dwightwatson commented 5 months ago

The usingClient method takes an instance of Kreait\Firebase\Contract\Messaging::class. All that example is showing you is getting an instance of that class from Laravel's container. You can instead get your own instance and pass it into the message as you like. Hope this helps.

masterbater commented 5 months ago

The usingClient method takes an instance of Kreait\Firebase\Contract\Messaging::class. All that example is showing you is getting an instance of that class from Laravel's container. You can instead get your own instance and pass it into the message as you like. Hope this helps.

My goals is to use a different project config on the fly. Please give an example of code.

dwightwatson commented 5 months ago

Inside your toFcm method create a new Firebase instance for the project you wish, and then pass the messaging component into the client method. You'll need to read up on the Kreait docs to see how to configure this as you need.

ashwin-nath-m commented 2 months ago

@masterbater can u share code for this?