PHP code example of joydeep-bhowmik / laravel-push-notification
1. Go to this page and download the library: Download joydeep-bhowmik/laravel-push-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/ */
joydeep-bhowmik / laravel-push-notification example snippets
return [
JoydeepBhowmik\LaravelPushNotification\Providers\FcmServiceProvider::class
];
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use Kreait\Firebase\Messaging\WebPushConfig;
use Kreait\Firebase\Messaging\ApnsConfig;
use Kreait\Firebase\Messaging\AndroidConfig;
class YourNotification extends Notification
{
public function via($notifiable)
{
return [FcmChannel::class];
}
public function toFcm($notifiable)
{
return [
// 'topic'=>'topic-name', if you want to send message in a topic
'notification' => [
'title' => 'Notification Title',
'body' => 'Notification body text.',
'icon' => 'https://your-server.example/icon.png',
],
'webpush' => [
'notification' => [
'title' => 'Notification Title',
'body' => 'Notification body text.',
'icon' => 'https://your-server.example/icon.png',
],
],
'android' => [
'notification' => [
'title' => 'Android Notification Title',
'body' => 'Android notification body text.',
'icon' => 'android-icon',
'color' => '#f45342',
],
],
'apns' => [
'payload' => [
'aps' => [
'alert' => [
'title' => 'APNs Notification Title',
'body' => 'APNs notification body text.',
],
'badge' => 42,
'sound' => 'default',
],
],
],
];
}
}
bash
php artisan vendor:publish --tag=fcm-all
php artisan vendor:publish --tag=fcm-tokens-model
bash
php artisan migrate