added kashkool

This commit is contained in:
2026-06-11 22:08:47 +03:30
parent 779a67a23e
commit 2d177ad581
24 changed files with 1575 additions and 3 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use App\Models\Pargar;
use App\Jobs\LogRouteCustomerJob;
use Illuminate\Support\Facades\Http;
class LogRequests
{
public function handle(Request $request, Closure $next)
{
// زمان شروع بر حسب میلی‌ثانیه
$start = microtime(true);
try {
// لاگ قبل از اجرای کنترلر
$Pargar = new Pargar();
$Pargar->ip = $request->ip();
$Pargar->m = $request->route()?->getName() ?? 'not_found';
//get action name from controller
if ($route = $request->route()) {
// تلاش برای گرفتن نام اکشن (کنترلر و متد)
$Pargar->function_name = $route->getActionName();
} else {
$Pargar->function_name = 'not_found';
}
$Pargar->finance_data = json_encode($request->all(), JSON_UNESCAPED_UNICODE);
$Pargar->finance_head = json_encode($request->headers->all(), JSON_UNESCAPED_UNICODE);
$Pargar->url = $request->fullUrl();
$Pargar->method = $request->method();
$Pargar->save();
} catch (\Throwable $e) {
$Pargar = null; // برای اطمینان از عدم خطا در ادامه
}
// اجرای درخواست اصلی
$response = $next($request);
try {
if ($Pargar) {
// if ($route = $request->route()) {
// try {
// $Pargar->m = $route
// ? $route->getActionName() . ' (' . (new \ReflectionClass($route->getController()))->getFileName() . ')'
// : 'unknown';
// } catch (\Throwable $e) {
// $Pargar->m = 'unknown';
// }
//
// }
$Pargar->response = $response->getContent();
$Pargar->ms = round((microtime(true) - $start) * 1000, 2); // زمان در میلی‌ثانیه
$Pargar->save();
}
} catch (\Throwable $e) {}
return $response;
}
}