@@ -288,8 +288,10 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
288
288
}
289
289
}
290
290
291
- if ($ this ->shouldCollect ('db ' , true ) && isset ($ this ->app ['db ' ])) {
292
- $ db = $ this ->app ['db ' ];
291
+ if ($ this ->shouldCollect ('db ' , true ) && isset ($ this ->app ['db ' ]) && isset ($ this ->app ['events ' ])) {
292
+ /** @var \Illuminate\Events\Dispatcher $events */
293
+ $ events = $ this ->app ['events ' ];
294
+
293
295
if (
294
296
$ debugbar ->hasCollector ('time ' ) && $ this ->app ['config ' ]->get (
295
297
'debugbar.options.db.timeline ' ,
@@ -336,7 +338,7 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
336
338
$ this ->addCollector ($ queryCollector );
337
339
338
340
try {
339
- $ db ->listen (
341
+ $ events ->listen (
340
342
function (\Illuminate \Database \Events \QueryExecuted $ query ) {
341
343
if (!app (static ::class)->shouldCollect ('db ' , true )) {
342
344
return ; // Issue 776 : We've turned off collecting after the listener was attached
@@ -354,49 +356,49 @@ function (\Illuminate\Database\Events\QueryExecuted $query) {
354
356
}
355
357
356
358
try {
357
- $ db -> getEventDispatcher () ->listen (
359
+ $ events ->listen (
358
360
\Illuminate \Database \Events \TransactionBeginning::class,
359
361
function ($ transaction ) use ($ queryCollector ) {
360
362
$ queryCollector ->collectTransactionEvent ('Begin Transaction ' , $ transaction ->connection );
361
363
}
362
364
);
363
365
364
- $ db -> getEventDispatcher () ->listen (
366
+ $ events ->listen (
365
367
\Illuminate \Database \Events \TransactionCommitted::class,
366
368
function ($ transaction ) use ($ queryCollector ) {
367
369
$ queryCollector ->collectTransactionEvent ('Commit Transaction ' , $ transaction ->connection );
368
370
}
369
371
);
370
372
371
- $ db -> getEventDispatcher () ->listen (
373
+ $ events ->listen (
372
374
\Illuminate \Database \Events \TransactionRolledBack::class,
373
375
function ($ transaction ) use ($ queryCollector ) {
374
376
$ queryCollector ->collectTransactionEvent ('Rollback Transaction ' , $ transaction ->connection );
375
377
}
376
378
);
377
379
378
- $ db -> getEventDispatcher () ->listen (
380
+ $ events ->listen (
379
381
'connection.*.beganTransaction ' ,
380
382
function ($ event , $ params ) use ($ queryCollector ) {
381
383
$ queryCollector ->collectTransactionEvent ('Begin Transaction ' , $ params [0 ]);
382
384
}
383
385
);
384
386
385
- $ db -> getEventDispatcher () ->listen (
387
+ $ events ->listen (
386
388
'connection.*.committed ' ,
387
389
function ($ event , $ params ) use ($ queryCollector ) {
388
390
$ queryCollector ->collectTransactionEvent ('Commit Transaction ' , $ params [0 ]);
389
391
}
390
392
);
391
393
392
- $ db -> getEventDispatcher () ->listen (
394
+ $ events ->listen (
393
395
'connection.*.rollingBack ' ,
394
396
function ($ event , $ params ) use ($ queryCollector ) {
395
397
$ queryCollector ->collectTransactionEvent ('Rollback Transaction ' , $ params [0 ]);
396
398
}
397
399
);
398
400
399
- $ db -> getEventDispatcher () ->listen (
401
+ $ events ->listen (
400
402
function (\Illuminate \Database \Events \ConnectionEstablished $ event ) use ($ queryCollector ) {
401
403
$ queryCollector ->collectTransactionEvent ('Connection Established ' , $ event ->connection );
402
404
0 commit comments