Skip to content

Commit 29166a0

Browse files
committed
chore: dont get raw route on console mode
1 parent 2818b65 commit 29166a0

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

app/Audit/AuditEventListener.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Illuminate\Support\Facades\App;
1818
use Illuminate\Support\Facades\Log;
1919
use Illuminate\Support\Facades\Route;
20-
20+
use Illuminate\Http\Request;
2121
/**
2222
* Class AuditEventListener
2323
* @package App\Audit
@@ -99,15 +99,16 @@ private function buildAuditContext(): AuditContext
9999
//$ui = app()->bound('ui.context') ? app('ui.context') : [];
100100

101101
$req = request();
102-
103-
try {
104-
$route = Route::getRoutes()->match($req);
105-
$method = $route->methods[0] ?? 'UNKNOWN';
106-
$rawRoute = $method . self::ROUTE_METHOD_SEPARATOR . $route->uri;
107-
}
108-
catch (\Exception $e) {
109-
Log::warning($e);
110-
$rawRoute = null;
102+
$rawRoute = null;
103+
// does not resolve the route when app is running in console mode
104+
if ($req instanceof Request && !app()->runningInConsole()) {
105+
try {
106+
$route = Route::getRoutes()->match($req);
107+
$method = $route->methods[0] ?? 'UNKNOWN';
108+
$rawRoute = $method . self::ROUTE_METHOD_SEPARATOR . $route->uri;
109+
} catch (\Exception $e) {
110+
Log::warning($e);
111+
}
111112
}
112113

113114
return new AuditContext(

0 commit comments

Comments
 (0)