diff --git a/src/Middleware/LogOperation.php b/src/Middleware/LogOperation.php index ba52f29ea2..7f0d069174 100644 --- a/src/Middleware/LogOperation.php +++ b/src/Middleware/LogOperation.php @@ -28,7 +28,11 @@ public function handle(Request $request, \Closure $next) 'input' => json_encode($request->input()), ]; - OperationLogModel::create($log); + try { + OperationLogModel::create($log); + } catch (\Exception $exception) { + // pass + } } return $next($request); @@ -42,27 +46,27 @@ public function handle(Request $request, \Closure $next) protected function shouldLogOperation(Request $request) { return config('admin.operation_log.enable') - && !$this->inExceptArray($request) && $this->inAllowedMethods($request->method()) + && !$this->inExceptArray($request) + && $this->inAllowedMethods($request->method()) && Admin::user(); } - /** - * @param $method + * Whether requests using this method are allowed to be logged. + * + * @param string $method * * @return bool */ - protected function inAllowedMethods($method) { - $allowed_methods = array_map('strtoupper', (array)config('admin.operation_log.allowed_methods')); - if (empty($allowed_methods)) { + protected function inAllowedMethods($method) + { + $allowedMethods = collect(config('admin.operation_log.allowed_methods'))->filter(); + + if ($allowedMethods->isEmpty()) { return true; - } else { - if (in_array($method, $allowed_methods)) { - return true; - } else { - return false; - } } + + return $allowedMethods->map('strtoupper')->contains($method); } /**