1. Go to this page and download the library: Download kemalnw/laravel-fcm 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/ */
kemalnw / laravel-fcm example snippets
/**
* Define your firebase server key
*/
return [
'server_key' => env('FIREBASE_SERVER_KEY', ''),
];
/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return ['fcm'];
}
use Fcm;
...
/**
* Get the FCM representation of the notification.
*
* @param mixed $notifiable
* @return void
*/
public function toFcm($notifiable)
{
return Fcm::notification([
'title' => 'Hi!',
'body' => 'This is my first notification.'
])
->timeToLive(604800); // 7 days in second
}
...
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the FCM channel.
*
* @param \Illuminate\Notifications\Notification $notification
* @return string
*/
public function routeNotificationForFcm($notification)
{
return $this->firebase_uid;
}
}
use Fcm;
...
/**
* Get the FCM representation of the notification.
*
* @param mixed $notifiable
* @return void
*/
public function toFcm($notifiable)
{
return Fcm::notification([
'title' => 'Hi!',
'body' => 'This is my first notification.'
])
->timeToLive(604800) // 7 days in second
->toTopic('topic-name');
}
sh
php artisan vendor:publish --tag="fcm"
sh
php artisan make:notification SomeNotification
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.