@@ -288,8 +288,10 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
288288 }
289289 }
290290
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+
293295 if (
294296 $ debugbar ->hasCollector ('time ' ) && $ this ->app ['config ' ]->get (
295297 'debugbar.options.db.timeline ' ,
@@ -336,7 +338,7 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
336338 $ this ->addCollector ($ queryCollector );
337339
338340 try {
339- $ db ->listen (
341+ $ events ->listen (
340342 function (\Illuminate \Database \Events \QueryExecuted $ query ) {
341343 if (!app (static ::class)->shouldCollect ('db ' , true )) {
342344 return ; // Issue 776 : We've turned off collecting after the listener was attached
@@ -354,49 +356,49 @@ function (\Illuminate\Database\Events\QueryExecuted $query) {
354356 }
355357
356358 try {
357- $ db -> getEventDispatcher () ->listen (
359+ $ events ->listen (
358360 \Illuminate \Database \Events \TransactionBeginning::class,
359361 function ($ transaction ) use ($ queryCollector ) {
360362 $ queryCollector ->collectTransactionEvent ('Begin Transaction ' , $ transaction ->connection );
361363 }
362364 );
363365
364- $ db -> getEventDispatcher () ->listen (
366+ $ events ->listen (
365367 \Illuminate \Database \Events \TransactionCommitted::class,
366368 function ($ transaction ) use ($ queryCollector ) {
367369 $ queryCollector ->collectTransactionEvent ('Commit Transaction ' , $ transaction ->connection );
368370 }
369371 );
370372
371- $ db -> getEventDispatcher () ->listen (
373+ $ events ->listen (
372374 \Illuminate \Database \Events \TransactionRolledBack::class,
373375 function ($ transaction ) use ($ queryCollector ) {
374376 $ queryCollector ->collectTransactionEvent ('Rollback Transaction ' , $ transaction ->connection );
375377 }
376378 );
377379
378- $ db -> getEventDispatcher () ->listen (
380+ $ events ->listen (
379381 'connection.*.beganTransaction ' ,
380382 function ($ event , $ params ) use ($ queryCollector ) {
381383 $ queryCollector ->collectTransactionEvent ('Begin Transaction ' , $ params [0 ]);
382384 }
383385 );
384386
385- $ db -> getEventDispatcher () ->listen (
387+ $ events ->listen (
386388 'connection.*.committed ' ,
387389 function ($ event , $ params ) use ($ queryCollector ) {
388390 $ queryCollector ->collectTransactionEvent ('Commit Transaction ' , $ params [0 ]);
389391 }
390392 );
391393
392- $ db -> getEventDispatcher () ->listen (
394+ $ events ->listen (
393395 'connection.*.rollingBack ' ,
394396 function ($ event , $ params ) use ($ queryCollector ) {
395397 $ queryCollector ->collectTransactionEvent ('Rollback Transaction ' , $ params [0 ]);
396398 }
397399 );
398400
399- $ db -> getEventDispatcher () ->listen (
401+ $ events ->listen (
400402 function (\Illuminate \Database \Events \ConnectionEstablished $ event ) use ($ queryCollector ) {
401403 $ queryCollector ->collectTransactionEvent ('Connection Established ' , $ event ->connection );
402404
0 commit comments