PHP code example of katsana / fcm-notification

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

    

katsana / fcm-notification example snippets


use NotificationChannels\Fcm\Message;

// ...

/**
 * Get the FCM representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \NotificationChannels\Fcm\Message
 */
public function toFcm($notifiable)
{
    return (new Message)
        ->notification('Your title', 'Your body');
}



namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

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->deviceToken;
    }
}

php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" --tag=config