@@ -101,13 +101,13 @@ protected static function buildLogContext(QueryException $e, int $attempt, int $
101101 $ sql = method_exists ($ e , 'getSql ' ) ? $ e ->getSql () : null ;
102102 $ bindings = method_exists ($ e , 'getBindings ' ) ? $ e ->getBindings () : [];
103103
104- // Try to read connection name
105- $ connectionName = null ;
106- try {
107- $ connection = DB :: connection ();
108- $ connectionName = $ connection ?->getName() ;
109- } catch ( Throwable ) {
110- // ignore
104+ $ connectionName = $ e -> getConnectionName ();
105+ $ conn = DB :: connection ( $ connectionName ) ;
106+
107+ // if laravel version <= 11.x then getRawSql() is not available and we will do it manually
108+ $ rawSql = method_exists ( $ e , ' getRawSql ' ) ? $ e -> getRawSql () : null ;
109+ if ( is_null ( $ rawSql ) && ! is_null ( $ sql ) && ! empty ( $ bindings ) ) {
110+ $ rawSql = $ conn -> getQueryGrammar ()-> substituteBindingsIntoRawSql ( $ sql , $ bindings );
111111 }
112112
113113 $ requestData = [
@@ -136,11 +136,8 @@ protected static function buildLogContext(QueryException $e, int $attempt, int $
136136 'attempt ' => $ attempt ,
137137 'maxRetries ' => $ maxRetries ,
138138 'trxLabel ' => $ trxLabel ,
139- 'Exception ' => get_class ($ e ),
140- 'message ' => $ e ->getMessage (),
141- 'sql ' => $ sql ,
142- 'bindings ' => stringifyBindings ($ bindings ),
143139 'errorInfo ' => $ e ->errorInfo ,
140+ 'rawSql ' => $ rawSql ,
144141 'connection ' => $ connectionName ,
145142 'trace ' => getDebugBacktraceArray (),
146143 ]);
0 commit comments