PHP code example of yusefarianpour / the-laravel-fcm-channel
1. Go to this page and download the library: Download yusefarianpour/the-laravel-fcm-channel 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/ */
yusefarianpour / the-laravel-fcm-channel example snippets
'fcm' => [
'key' => 'Your Firebase Cloud Messaging token',
],
public function via($notifiable)
{
return ['fcm'];
}
use Journalctl\Channels\FirebaseChannel;
...
public function via($notifiable)
{
return [FirebaseChannel::class];
}
use Journalctl\Channels\FirebaseChannel;
use Journalctl\Channels\FirebaseMessage;
...
public function toFcm($notifiable)
{
$message = new FirebaseMessage();
$message
->title('Foo') // Required
->body('Bar') // Required
->sound() // Optional
->icon() // Optional
->clickAction(); // Optional
$message->data([
'param1' => 'baz' // Optional
])->priority(FirebaseMessage::PRIORITY_HIGH); // Optional - Default is 'normal'.
return $message;
}
/**
* Route notifications for the Firebase Cloud Messaging channel.
*
* @return string
*/
public function routeNotificationForFcm()
{
return $this->device_token;
}
bash
php artisan make:notification SomeNotification