Skip to content

Commit

Permalink
[refactor]
Browse files Browse the repository at this point in the history
  • Loading branch information
z-song committed Sep 19, 2018
1 parent 1c185b8 commit c6c727c
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/Middleware/LogOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit c6c727c

Please sign in to comment.