From 17afbae62e47696443904413644d2f5ad2eafcd5 Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 8 Jun 2017 04:00:45 -0500 Subject: [PATCH] Fixed 506c1eb for Laravel 5.1 Support (#648) --- src/LaravelDebugbar.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/LaravelDebugbar.php b/src/LaravelDebugbar.php index 97d10439..cfe849ab 100644 --- a/src/LaravelDebugbar.php +++ b/src/LaravelDebugbar.php @@ -348,21 +348,45 @@ function ($query, $bindings = null, $time = null, $connectionName = null) use ($ \Illuminate\Database\Events\TransactionBeginning::class, 'connection.*.beganTransaction', ], function ($transaction) use ($queryCollector) { - $queryCollector->collectTransactionEvent('Begin Transaction', $transaction->connection); + + // Laravel 5.2 changed the way some core events worked. We must account for + // the first argument being an "event object", where arguments are passed + // via object properties, instead of individual arguments. + if($transaction instanceof \Illuminate\Database\Events\TransactionBeginning) { + $connection = $transaction->connection; + } else { + $connection = $transaction; + } + + $queryCollector->collectTransactionEvent('Begin Transaction', $connection); }); $db->getEventDispatcher()->listen([ \Illuminate\Database\Events\TransactionCommitted::class, 'connection.*.committed', ], function ($transaction) use ($queryCollector) { - $queryCollector->collectTransactionEvent('Commit Transaction', $transaction->connection); + + if($transaction instanceof \Illuminate\Database\Events\TransactionCommitted) { + $connection = $transaction->connection; + } else { + $connection = $transaction; + } + + $queryCollector->collectTransactionEvent('Commit Transaction', $connection); }); $db->getEventDispatcher()->listen([ \Illuminate\Database\Events\TransactionRolledBack::class, 'connection.*.rollingBack', ], function ($transaction) use ($queryCollector) { - $queryCollector->collectTransactionEvent('Rollback Transaction', $transaction->connection); + + if($transaction instanceof \Illuminate\Database\Events\TransactionRolledBack) { + $connection = $transaction->connection; + } else { + $connection = $transaction; + } + + $queryCollector->collectTransactionEvent('Rollback Transaction', $connection); }); } catch (\Exception $e) { $this->addThrowable(