spatie/laravel-artisan-dd
Run one-off Laravel code from the command line without opening Tinker. Use php artisan dd "User::first()" to execute expressions and dump results. Supports multiple expressions and short class names for quick debugging and inspection.
Installation:
composer require spatie/laravel-artisan-dd
No additional configuration is required—just publish the package.
First Use Case:
Run a quick dd()-like dump from the command line:
php artisan dd "User::first()"
This will output the first user record in a readable format, halting execution (just like dd() in code).
Where to Look First:
Debugging Queries or Models:
php artisan dd "User::where('active', true)->get()"
Useful for inspecting Eloquent results without booting Tinker.
Testing Configuration Values:
php artisan dd "config('app.debug')"
Quickly verify app settings during development.
Inspecting Service Container Bindings:
php artisan dd "app()->bound('App\\Services\\SomeService') ? app('App\\Services\\SomeService') : 'Not bound'"
Check if a service is registered and its state.
Debugging Middleware or Route Logic:
php artisan dd "request()->headers->all()"
Dump request data directly from the CLI.
Integration with CI/CD:
Add to scripts in package.json or Makefile for automated debugging:
{
"scripts": {
"debug:user": "php artisan dd \"User::first()\""
}
}
Combining with Other Artisan Commands:
Pipe output to other tools (e.g., jq for JSON parsing):
php artisan dd "User::first()" | jq
artisan dd for ad-hoc debugging.artisan tinker:
Use tinker for interactive sessions and dd for quick, scripted checks.artisan dd commands to a DEBUG.md file in your project for team reference.if [ "$DEBUG_MODE" = "true" ]; then
php artisan dd "User::all()->count()"
fi
~/.bashrc):
alias ddd='php artisan dd'
Now use ddd "Model::query()->toSql()" for brevity.artisan dd in deployment scripts to verify critical data post-deploy.Output Truncation:
Large datasets may truncate output. Use --no-truncate (if supported) or pipe to a file:
php artisan dd "User::all()" > debug_users.txt
Note: The package may not support --no-truncate natively; check the issue tracker.
Syntax Errors: PHP syntax errors in the command line will halt execution. Validate syntax first:
php -r "User::first();" # Test syntax before using `artisan dd`
Environment Mismatches:
Ensure the command runs in the correct environment (e.g., .env variables may differ between local/staging/prod). Use:
php artisan dd "app()->environment()" # Verify environment
Performance Impact:
Avoid running dd on production-like data in development. Use --force cautiously:
php artisan dd --force "User::with('posts')->get()" # May be slow!
Dependency on Laravel Context: The command runs within Laravel’s context, so:
AppServiceProvider).php artisan dd "new \App\Models\User" for stateless checks.Inspect Command Logic:
The package adds a dd command to app/Console/Kernel.php. Override it for custom behavior:
protected $commands = [
\Spatie\ArtisanDd\ArtisanDdCommand::class,
// Custom commands...
];
Check for Updates: The package is actively maintained (last release: 2026). Update regularly:
composer update spatie/laravel-artisan-dd
Fallback to Tinker:
If artisan dd fails, fall back to Tinker:
php artisan tinker --execute="User::first(); exit;"
Combine with tap for Chaining:
Use Laravel’s tap() to inspect intermediate results:
php artisan dd "User::first()->tap(fn($user) => dd($user->posts))"
Debug Exceptions: Catch exceptions in the command line:
php artisan dd "try { User::find(999); } catch (\Exception $e) { dd($e->getMessage()); }"
Use with Laravel Sail: Debug containers directly:
sail artisan dd "DB::connection()->getPdo()"
Custom Formatting:
Extend the package by overriding the dump() method in a service provider:
use Spatie\ArtisanDd\ArtisanDdCommand;
ArtisanDdCommand::macro('customDump', function ($value) {
dd(json_encode($value, JSON_PRETTY_PRINT));
});
Then use:
php artisan dd "User::first(); customDump(User::all())"
Log Output to File: Redirect output for later analysis:
php artisan dd "User::all()" > /tmp/debug_users.log
Performance Profiling: Measure execution time:
php artisan dd "User::all(); dd(microtime(true) - LARAVEL_START);"
How can I help you explore Laravel packages today?