Download the PHP package tusharkhan/db-error-explainer-laravel without Composer
On this page you can find all versions of the php package tusharkhan/db-error-explainer-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tusharkhan/db-error-explainer-laravel
More information about tusharkhan/db-error-explainer-laravel
Files in tusharkhan/db-error-explainer-laravel
Package db-error-explainer-laravel
Short Description Explains Laravel database errors in plain language with a suggested fix: Ignition solutions, a facade and Artisan commands
License MIT
Homepage https://github.com/tusharkhan/db-error-explainer-laravel
Informations about the package db-error-explainer-laravel
DB Error Explainer for Laravel
Explains Laravel database errors in plain language, with a suggested fix, right on the error page.
Works with MySQL / MariaDB, PostgreSQL and SQLite connections.
Requirements
- PHP 8.4+
- Laravel 12 or 13
- Optional:
spatie/laravel-ignitionto see explanations on the error page
Installation
The service provider and the DbExplainer facade are auto-discovered.
What you get
On the Ignition error page
When a QueryException reaches the error page, Ignition shows a "Database error explained" solution with:
- what went wrong, using the table and column names from your schema
- a SQL fix when there is one
- a Laravel tip (e.g.
foreignId()->constrained(),Schema::defaultStringLength(191),firstOrCreate())
Nothing to configure; it is enabled when Ignition is installed.
In code
explain() uses the connection the exception came from. It returns null for non-database exceptions, unsupported drivers (e.g. sqlsrv) or when disabled. It never throws.
Connection failures (wrong password, server down) are explained too, without trying to reconnect.
From the command line
Paste an error from storage/logs/laravel.log (the (Connection: ..., SQL: ...) part can stay):
Turn the suggested fix into a migration you can review and run:
The stub runs the SQL with DB::unprepared(). The command warns when the fix lists alternatives or contains placeholders like your_table to replace first.
Both commands read the message only; they never run the failing query. Options:
| Option | |
|---|---|
--connection= |
Connection the error came from (decides MySQL / PostgreSQL / SQLite rules). Default connection when omitted |
--no-schema |
Don't connect to look up table and column details |
--sqlstate=, --code= |
Fill these in when the pasted text doesn't start with SQLSTATE[...] |
--json |
db:explain only: print the full diagnosis as JSON |
--path= |
db:fix-stub only: directory for the migration |
In your logs
Set DB_EXPLAINER_LOG=true and every reported QueryException also writes a Database error diagnosed entry with the error type and explanation.
Configuration
| Key | Env | Default | |
|---|---|---|---|
enabled |
DB_EXPLAINER_ENABLED |
true |
Turn everything off |
allow_introspection |
DB_EXPLAINER_INTROSPECTION |
true |
Read-only schema lookups for more specific explanations |
redact_sensitive_data |
DB_EXPLAINER_REDACT |
true |
Hide password, token, api_key, ... values |
log |
DB_EXPLAINER_LOG |
false |
Log an explanation for each reported database error |
log_channel |
DB_EXPLAINER_LOG_CHANNEL |
null |
Channel for those entries (default channel when null) |
ignition |
DB_EXPLAINER_IGNITION |
true |
Add the solution to the Ignition error page |
custom_rules |
[] |
Your own rules, same array format as the built-in ones |
License
MIT. See LICENSE.
All versions of db-error-explainer-laravel with dependencies
illuminate/console Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
tusharkhan/db-error-explainer-core Version ^1.0
tusharkhan/db-error-explainer-lib Version ^1.0