LD 5 лет назад
Родитель
Сommit
e11c3fc03a
1 измененных файлов с 10 добавлено и 16 удалено
  1. 10 16
      app/Services/LogService.php

+ 10 - 16
app/Services/LogService.php

@@ -18,29 +18,23 @@ class LogService
             $user = auth()->user();
             if ($user) $id_user = $user['id'];
         }
+        $log=new Log([
+            'operation' => $method,
+            'type' => $type,
+            'description' => $description,
+            'id_user' => $id_user,
+            'ip' => request()->ip(),
+        ]);
         try {
             Redis::LLEN('LOGS');
         } catch (Exception $e) {
             //redis出现异常直接保存到数据库中
-            (new Log([
-                'operation' => $method,
-                'type' => $type,
-                'description' => $description,
-                'id_user' => $id_user,
-                'ip' => request()->ip(),
-            ]))->save();
+            $log->save();
             return;
         }
         $date = date('Y-m-d H:i:s');
-        $log = new Log([
-            'operation' => $method,
-            'type' => $type,
-            'description' => $description,
-            'id_user' => $id_user,
-            'ip' => Request::ip(),
-            'created_at' => $date,
-            'updated_at' => $date
-        ]);
+        $log['created_at']=$date;
+        $log['updated_at']=$date;
         Redis::LPUSH('LOGS', $log);
     }