Преглед на файлове

update fcm token with middleware

Alexander Musikhin преди 2 месеца
родител
ревизия
ff76fdd016
променени са 4 файла, в които са добавени 37 реда и са изтрити 3 реда
  1. 29 0
      app/Http/Middleware/CatchTokenFcmMiddleware.php
  2. 2 0
      bootstrap/app.php
  3. 0 3
      routes/web.php
  4. 6 0
      todo.md

+ 29 - 0
app/Http/Middleware/CatchTokenFcmMiddleware.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use App\Models\User;
+use Closure;
+use Illuminate\Http\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+class CatchTokenFcmMiddleware
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
+     */
+    public function handle(Request $request, Closure $next): Response
+    {
+        if(isset($request->app) && isset($request->token_fcm)) {
+            if(auth()->check()) {
+                User::query()
+                    ->where('id', auth()->user()->id)
+                    ->update(['token_fcm' => $request->token_fcm]);
+            }
+            session(['token_fcm' => $request->token_fcm]);
+        }
+        return $next($request);
+    }
+}

+ 2 - 0
bootstrap/app.php

@@ -1,5 +1,6 @@
 <?php
 
+use App\Http\Middleware\CatchTokenFcmMiddleware;
 use App\Http\Middleware\EnsureUserHasRole;
 use Illuminate\Foundation\Application;
 use Illuminate\Foundation\Configuration\Exceptions;
@@ -16,6 +17,7 @@ return Application::configure(basePath: dirname(__DIR__))
         $middleware->alias([
             'role' => EnsureUserHasRole::class,
         ]);
+        $middleware->append(CatchTokenFcmMiddleware::class);
     })
     ->withExceptions(function (Exceptions $exceptions) {
         //

+ 0 - 3
routes/web.php

@@ -17,9 +17,6 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Route;
 
 Route::get('/', function () {
-    if(isset(request()->app) && isset(request()->token_fcm)) {
-        session(['token_fcm' => request()->token_fcm]);
-    }
     return redirect()->route('home');
 });
 

+ 6 - 0
todo.md

@@ -28,3 +28,9 @@
 - [ ] фильтры как в экселе
 - [x] вывод отчетов (сколько смонтировано, сколько осталось и т.д.)
 - [ ] мобильная верстка
+
+
+- middleware for token get/update
+- install fcm notification channel for notify users
+- triggers for notify users
+- export scheduler to excel