update: add request log to middleware

This commit is contained in:
v2board 2023-06-01 23:31:56 +08:00
parent 1b8ec77bcc
commit 2285a7c92f
4 changed files with 28 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\Log;
use App\Models\Plan; use App\Models\Plan;
use App\Models\StatServer; use App\Models\StatServer;
use App\Models\StatUser; use App\Models\StatUser;
@ -46,5 +47,6 @@ class ResetLog extends Command
{ {
StatUser::where('record_at', '<', strtotime('-2 month', time()))->delete(); StatUser::where('record_at', '<', strtotime('-2 month', time()))->delete();
StatServer::where('record_at', '<', strtotime('-2 month', time()))->delete(); StatServer::where('record_at', '<', strtotime('-2 month', time()))->delete();
Log::where('created_at', '<', strtotime('-1 month', time()))->delete();
} }
} }

View File

@ -70,6 +70,7 @@ class Kernel extends HttpKernel
'admin' => \App\Http\Middleware\Admin::class, 'admin' => \App\Http\Middleware\Admin::class,
'client' => \App\Http\Middleware\Client::class, 'client' => \App\Http\Middleware\Client::class,
'staff' => \App\Http\Middleware\Staff::class, 'staff' => \App\Http\Middleware\Staff::class,
'log' => \App\Http\Middleware\RequestLog::class
]; ];
/** /**

View File

@ -0,0 +1,24 @@
<?php
namespace App\Http\Middleware;
use Closure;
class RequestLog
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->method() === 'POST') {
$path = $request->path();
info("POST {$path}");
};
return $next($request);
}
}

View File

@ -9,7 +9,7 @@ class AdminRoute
{ {
$router->group([ $router->group([
'prefix' => config('v2board.secure_path', config('v2board.frontend_admin_path', hash('crc32b', config('app.key')))), 'prefix' => config('v2board.secure_path', config('v2board.frontend_admin_path', hash('crc32b', config('app.key')))),
'middleware' => 'admin' 'middleware' => ['admin', 'log']
], function ($router) { ], function ($router) {
// Config // Config
$router->get ('/config/fetch', 'Admin\\ConfigController@fetch'); $router->get ('/config/fetch', 'Admin\\ConfigController@fetch');