🚀 Feature Request: Add QueryFailed event for failed database queries #57152
Unanswered
vinitkadam03
asked this question in
Ideas
Replies: 1 comment 5 replies
-
@vinitkadam03 ![]() The query exception has the connection name, query and bindings <?php
namespace Illuminate\Database\Events;
use Illuminate\Database\QueryException;
class QueryFailed
{
public function __construct(
public QueryException $queryException
) {
}
} Can this be considered a breaking change? Yes because the objects are passes with memory address and any change to them is persisted. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Laravel currently provides a
QueryExecuted
event that fires after a database query has succeeded.However, there is no equivalent event for failed queries.
This creates a few limitations:
QueryException
but is caught by user code (i.e. never reaches the exception handler), there’s no way to centrally observe or log it.Connection::run()
or wrap drivers manually.Proposal
Introduce a new event:
Illuminate\Database\Events\QueryFailed
, fired whenever a database query fails with aQueryException
.Proposed event payload:
$sql
(string): the SQL query$bindings
(array): the bound parameters$connectionName
(string): the connection name$exception
(QueryException): the exception objectExample Usage
Implementation Sketch
New Event Class
Benefits
QueryExecuted
) and failed (QueryFailed
) queries.Considerations
💡 This would align well with Laravel’s existing event system and make DB monitoring more robust out of the box.
Beta Was this translation helpful? Give feedback.
All reactions