kint-php/kint
Kint is a powerful PHP debugging and profiling tool that dumps variables with rich, readable output (CLI and browser). It offers deep inspection of arrays/objects, stack traces, timing/memory info, and easy integration for faster troubleshooting in any PHP project.
Installation:
composer require kint-php/kint
No additional configuration is required—Kint auto-detects Laravel and integrates seamlessly.
First Use:
Replace var_dump() or dd() with:
kint($yourVariable); // For inline inspection
Or use the Laravel-friendly dd() alias (if enabled):
dd($yourVariable); // Dumps and dies (same as Laravel's dd)
Where to Look First:
$user = User::with('posts')->find(1);
kint($user); // Inspect the entire Eloquent relationship tree
kint($user->toArray()) to flatten the output for simpler inspection.var_dump() and dd()kint($request->all()); // Inspect incoming request data
dd($this->someComplexObject); // Kint + die (Laravel-compatible)
kint($this->getSomeData()); // Colorized CLI output
kint($job->payload()); // Debug failed jobs
kint(memory_get_usage(), memory_get_peak_usage());
$start = microtime(true);
// ... code ...
kint(microtime(true) - $start);
kint($request->headers->all()); // Inspect incoming headers
kint(app()->bound('some.bound.service')); // Check if a service is bound
kint($event->data); // Inspect event payloads
use Kint\Kint;
Kint::registerDumper(User::class, function ($user) {
return [
'id' => $user->id,
'name' => $user->name,
'posts_count' => $user->posts()->count(),
];
});
Add Kint to Laravel’s AppServiceProvider for global access:
public function boot()
{
if ($this->app->environment('local')) {
\Kint::register();
}
}
kint(json_decode($response->getContent(), true));
kint([
'request' => $request->all(),
'response' => $response->getData(),
]);
Performance Overhead:
if (app()->environment('local')) {
kint($data);
}
Recursive Data:
User <-> Role many-to-many).kint($user, ['maxDepth' => 3]);
Or configure globally in config/kint.php:
'maxDepth' => 5,
CLI vs. Web Rendering:
kint($data, ['renderer' => \Kint\Renderer\WebRenderer::class]);
Laravel Debugbar Conflict:
barryvdh/laravel-debugbar may clash.Sensitive Data Exposure:
$sanitized = collect($request->all())->except(['password', 'api_token']);
kint($sanitized);
Inspecting Closures/Lambdas:
kint($closure->getClosureThis()); // Inspect bound object
Database Query Debugging:
$query = User::where('active', true);
kint($query->toSql(), [$query->getBindings()]);
Symfony Components:
ParameterBag, ArrayAccess, etc.:
kint($request->query); // Symfony's ParameterBag
Custom Objects:
__debugInfo() for cleaner output:
class MyModel {
public function __debugInfo() {
return [
'id' => $this->id,
'name' => $this->name,
];
}
}
Global Configuration:
config/kint.php:
'enabled' => env('KINT_ENABLED', true),
'maxDepth' => 10,
'exclude' => [
'password',
'api_token',
'remember_token',
],
Renderer Switching:
Kint::setRenderer() dynamically:
\Kint::setRenderer(\Kint\Renderer\CliRenderer::class); // Force CLI
Plugin System:
\Kint::registerPlugin(new class {
public function getName() { return 'Laravel'; }
public function dump($data) {
if ($data instanceof \Illuminate\Database\Eloquent\Model) {
return $data->toArray();
}
}
});
Custom Dumper for Collections:
use Illuminate\Support\Collection;
use Kint\Kint;
Kint::registerDumper(Collection::class, function ($collection) {
return [
'count' => $collection->count(),
'first' => $collection->first(),
'last' => $collection->last(),
'keys' => $collection->keys()->toArray(),
];
});
Hook into Laravel Events:
Illuminate\Auth\Events\Registered):
event(new Registered($user));
kint($user); // Inspect the newly created user
TAP Testing:
public function testSomething()
{
$result = $this->someMethod();
kint($result); // Inspect during test runs
$this->assertTrue($result);
}
How can I help you explore Laravel packages today?