muradcade / laravel_peek
Send debug output from Laravel/PHP to the Peek desktop app
Requires
- php: ^8.0
- ext-curl: *
- ext-json: *
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Send values, SQL queries, stack traces and exceptions from your Laravel app straight to the Peek desktop app, without littering your browser or API responses with dd() output.
peek($user); // dump anything peek_label('Cart total', $sum); // dump with a label peek_trace(); // who called this?
Peek is fire-and-forget: if the Peek app is closed, your application keeps running at full speed and nothing breaks.
Features
- 🔍
peek()helper: dump one or many values; returns the first value so it can be chained - 🏷️ Labels: tag dumps so you can find them quickly
- 🧭 Origin tracking: every message records the file and line it came from
- 🗄️ SQL query logging: SQL, bindings and execution time (opt-in)
- 🚨 Exception reporting: reported exceptions appear in Peek (opt-in)
- 🪜 Stack traces:
peek_trace()sends a compact call stack - 🛡️ Safe by default: disabled automatically when
APP_DEBUG=false - ⚡ Non-blocking: 300 ms hard timeout, errors are silenced
Requirements
- PHP 8.0+
- Laravel 9.x or newer (uses
illuminate/support) - PHP extensions:
curl,json - The Peek desktop app, listening on
127.0.0.1:23517
Installation
Install as a development dependency:
composer require --dev muradcade/laravel_peek
The service provider and helper functions are registered automatically through Laravel package auto-discovery. No further setup is needed. .
Usage
Dump values
peek($order); peek($a, $b, $c); // multiple values, each sent separately
peek() returns its first argument, so you can drop it into an expression:
$total = peek($cart->total()) * 1.2;
Labelled dumps
peek_label('Payload', $request->all());
Returns the value, so it is chainable too.
Stack traces
peek_trace();
Sends the current call stack (class, method, file and line for each frame) to Peek.
Using the class directly
The helpers are thin wrappers around Peek\Peek:
use Peek\Peek; Peek::send('dump', $value, 'My label');
Logging SQL queries
Add to your .env:
PEEK_QUERIES=true
Every query is sent with its SQL, bindings and execution time in milliseconds.
Reporting exceptions
PEEK_EXCEPTIONS=true
Any exception passed through Laravel's exception reporter is sent to Peek, including class, message, file and line. Your existing exception handling is not changed.
Configuration
Peek is configured through environment variables:
| Variable | Default | Description |
|---|---|---|
PEEK_ENABLED |
value of APP_DEBUG |
Master switch for the query and exception listeners |
PEEK_QUERIES |
false |
Send every SQL query to Peek |
PEEK_EXCEPTIONS |
false |
Send reported exceptions to Peek |
To point Peek at a different host or port, set the URL at runtime, for example in a service provider:
\Peek\Peek::$url = 'http://127.0.0.1:23517/';
How it works
Each call sends a JSON POST to the Peek app:
{
"type": "dump",
"label": "Cart total",
"time": "14:32:07",
"origin": "CartController.php:42",
"data": { }
}
| Field | Description |
|---|---|
type |
dump, query, exception or trace |
label |
Optional label (null if none) |
time |
Time sent, H:i:s |
origin |
file.php:line of the calling code |
data |
The normalized value |
Values are normalized before sending:
- Objects become arrays with a
__classkey (usestoArray()when available, otherwise all properties including private and protected ones) - Exceptions are reduced to class, message and
file:line - Closures appear as
{"__class": "Closure"} - Resources become
resource(type) - Non-finite floats (
INF,NAN) become strings - Nesting deeper than 6 levels is truncated
Production safety
Peek is intended for local development only.
- Install it with
--dev - Leave
APP_DEBUG=falsein production, which disables the listeners - Remove stray
peek()calls before deploying. If the helper is not installed (for examplecomposer install --no-dev), calls topeek()will throw an undefined function error
Payloads are sent over plain HTTP to 127.0.0.1 and never leave your machine.
Note on config caching: Peek reads its settings with
env(). If you runphp artisan config:cachelocally,env()returnsnulloutside of config files, so the defaults apply. Runphp artisan config:clearduring development.
Troubleshooting
Nothing shows up in Peek
- Make sure the Peek app is running and listening on port
23517 - Check
APP_DEBUG=trueorPEEK_ENABLED=true - For queries or exceptions, confirm
PEEK_QUERIES/PEEK_EXCEPTIONSaretrue - If you use Docker, Sail or a VM,
127.0.0.1refers to the container. SetPeek::$urlto a host-reachable address such ashttp://host.docker.internal:23517/
Large objects look truncated
Depth is limited to 6 levels to keep payloads small.
Contributing
Issues and pull requests are welcome. Please open an issue first to discuss larger changes.
License
Released under the MIT License.