&$item) { if (preg_match("/(password|salt|token)/i", $index)) { $item = "***"; } else { if (is_array($item)) { $item = self::pureData($item); } } } return $data; } public static function record($title = '', $data = '') { $auth = Auth::instance(); $admin_id = $auth->isLogin() ? $auth->id : 0; $username = $auth->isLogin() ? $auth->username : __('Unknown'); $controller = str_replace('.', '/', request()->controller(true)); $action = request()->action(true); $path = $controller . '/' . $action; if (self::$urlIgnoreRegex) { foreach (self::$urlIgnoreRegex as $item) { if (preg_match($item, $path)) { return; } } } $data = $data ?: self::$data; if (!$data) { $data = request()->param('', null, 'trim,strip_tags,htmlspecialchars'); $data = self::pureData($data); } $title = $title ?: self::$title; if (!$title) { $controllerTitle = MenuRule::where('name', $controller)->value('title'); $title = MenuRule::where('name', $path)->value('title'); $title = $title ?: __('Unknown') . '(' . $action . ')'; $title = $controllerTitle ? ($controllerTitle . '-' . $title) : $title; } self::create([ 'admin_id' => $admin_id, 'username' => $username, 'url' => substr(request()->url(), 0, 1500), 'title' => $title, 'data' => !is_scalar($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data, 'ip' => request()->ip(), 'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255), ]); } public function admin() { return $this->belongsTo(Admin::class); } }