Ver Fonte

test fcm notifications

Alexander Musikhin há 1 mês atrás
pai
commit
5b400de3bd
6 ficheiros alterados com 120 adições e 1199 exclusões
  1. 5 0
      .env.example
  2. 10 0
      app/Models/User.php
  3. 43 0
      app/Notifications/FireBaseNotification.php
  4. 2 2
      composer.json
  5. 53 1197
      composer.lock
  6. 7 0
      config/syntechfcm.php

+ 5 - 0
.env.example

@@ -50,3 +50,8 @@ JWT_SECRET=c05c4346dc03362dabbf94c18a1befe78e9b301837f3163e43a57201d9cc09cb
 PAGINATION_LIMIT=2000
 
 WORDS_IN_TABLE_CELL_LIMIT=15
+
+# FCM settings
+FCM_PROJECT_ID=
+FCM_CLIENT_EMAIL=
+FCM_PRIVATE_KEY=

+ 10 - 0
app/Models/User.php

@@ -50,4 +50,14 @@ class User extends Authenticatable implements MustVerifyEmail
             'password' => 'hashed',
         ];
     }
+
+    /**
+     * Route notifications for the FCM channel.
+     *
+     * @return string
+     */
+    public function routeNotificationForFcm(): string
+    {
+        return $this->token_fcm;
+    }
 }

+ 43 - 0
app/Notifications/FireBaseNotification.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Notifications;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Notifications\Notification;
+
+class FireBaseNotification extends Notification
+{
+    use Queueable;
+
+    /**
+     * Create a new notification instance.
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Get the notification's delivery channels.
+     *
+     * @return array<int, string>
+     */
+    public function via(object $notifiable): array
+    {
+        return ['fcm'];
+    }
+
+    public function toFcm(object $notifiable): array
+    {
+        return [
+            'to' => $notifiable->token_fcm,
+            'notification' => [
+                'title'    => 'Notification Title',
+                'body'     => 'Notification Body',
+                'image'    => '', // Optional image URL
+            ],
+        ];
+    }
+}

+ 2 - 2
composer.json

@@ -8,12 +8,12 @@
         "php": "^8.2",
         "ext-pdo": "*",
         "ext-zip": "*",
-        "laravel-notification-channels/fcm": "^5.1",
         "laravel/framework": "^11.31",
         "laravel/tinker": "^2.9",
         "laravel/ui": "^4.6",
         "phpoffice/phpspreadsheet": "^3.6",
-        "predis/predis": "^2.3"
+        "predis/predis": "^2.3",
+        "syntech/syntechfcm": "^1.3"
     },
     "require-dev": {
         "fakerphp/faker": "^1.23",

Diff do ficheiro suprimidas por serem muito extensas
+ 53 - 1197
composer.lock


+ 7 - 0
config/syntechfcm.php

@@ -0,0 +1,7 @@
+<?php
+
+return [
+    'project_id' => env('FCM_PROJECT_ID'),
+    'client_email' => env('FCM_CLIENT_EMAIL'),
+    'private_key' => env('FCM_PRIVATE_KEY'),
+];

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff