https://github.com/loburets/laravel-query-printer
An easy way to print queries in Laravel 🖨️
https://github.com/loburets/laravel-query-printer
debug debugging laravel php sql
Last synced: 5 months ago
JSON representation
An easy way to print queries in Laravel 🖨️
- Host: GitHub
- URL: https://github.com/loburets/laravel-query-printer
- Owner: loburets
- License: mit
- Created: 2021-08-15T14:42:43.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-06T15:59:57.000Z (over 1 year ago)
- Last Synced: 2025-07-20T23:19:11.584Z (11 months ago)
- Topics: debug, debugging, laravel, php, sql
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🖨️ Laravel Query Printer
An easy way to print Laravel queries
## 📌 Example
```PHP
// Enable query log
\DB::enableQueryLog();
// Use whatever queries you want to debug:
User::where('email', 'test@test.com')->where('verified', true)->first();
User::where('id', '<', '5')->get();
// See what the queries were executed
\QueryPrinter::printQueryLog();
```
### 🔹 Output **without** this package:

### 🔹 Output **with** this package:

Now you can simply copy and execute the query without struggling with bindings 🙌
---
## 🚀 Installation
```Bash
composer require loburets/laravel-query-printer
```
For Laravel **< 5.5**, add the alias in `config/app.php`:
```PHP
'QueryPrinter' => Loburets\LaravelQueryPrinter\Facade::class,
```
---
## 🛠️ Usage
### ✅ Printing a Query Builder instance
You can print a query before execution:
```PHP
// Build your query, but don't call ->first(), ->get() etc. So it is an instance of the Query Builder here:
$query = \Model::where()->join()->etc();
// Print the generated SQL
\QueryPrinter::print($query);
```
### ✅ Printing executed queries from query logs
You can also print queries after they have been executed:
```PHP
// Enable the Query log:
\DB::enableQueryLog();
// Do any actions which you want to be logged:
$results = \Model::where()->join()->etc()->get();
// Print all the executed queries
\QueryPrinter::printQueryLog();
```
---
Now debugging Laravel queries is easier than ever! 🎯