Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Artisan Dd Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require spatie/laravel-artisan-dd
    

    No additional configuration is required—just publish the package.

  2. 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).

  3. Where to Look First:


Implementation Patterns

Usage Patterns

  1. Debugging Queries or Models:

    php artisan dd "User::where('active', true)->get()"
    

    Useful for inspecting Eloquent results without booting Tinker.

  2. Testing Configuration Values:

    php artisan dd "config('app.debug')"
    

    Quickly verify app settings during development.

  3. 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.

  4. Debugging Middleware or Route Logic:

    php artisan dd "request()->headers->all()"
    

    Dump request data directly from the CLI.

  5. Integration with CI/CD: Add to scripts in package.json or Makefile for automated debugging:

    {
      "scripts": {
        "debug:user": "php artisan dd \"User::first()\""
      }
    }
    
  6. Combining with Other Artisan Commands: Pipe output to other tools (e.g., jq for JSON parsing):

    php artisan dd "User::first()" | jq
    

Workflows

  • Replace Tinker for One-Liners: Avoid starting Tinker for trivial checks. Use artisan dd for ad-hoc debugging.
  • Pair with artisan tinker: Use tinker for interactive sessions and dd for quick, scripted checks.
  • Document Debugging Commands: Add artisan dd commands to a DEBUG.md file in your project for team reference.

Integration Tips

  • Environment-Specific Debugging: Use environment variables to toggle debug commands:
    if [ "$DEBUG_MODE" = "true" ]; then
      php artisan dd "User::all()->count()"
    fi
    
  • Custom Aliases: Add an alias to your shell config (e.g., ~/.bashrc):
    alias ddd='php artisan dd'
    
    Now use ddd "Model::query()->toSql()" for brevity.
  • Laravel Forge/Envoyer: Include artisan dd in deployment scripts to verify critical data post-deploy.

Gotchas and Tips

Pitfalls

  1. 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.

  2. 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`
    
  3. 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
    
  4. 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!
    
  5. Dependency on Laravel Context: The command runs within Laravel’s context, so:

    • Database connections must be configured.
    • Service providers must be registered (e.g., AppServiceProvider).
    • Use php artisan dd "new \App\Models\User" for stateless checks.

Debugging

  1. 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...
    ];
    
  2. Check for Updates: The package is actively maintained (last release: 2026). Update regularly:

    composer update spatie/laravel-artisan-dd
    
  3. Fallback to Tinker: If artisan dd fails, fall back to Tinker:

    php artisan tinker --execute="User::first(); exit;"
    

Tips

  1. Combine with tap for Chaining: Use Laravel’s tap() to inspect intermediate results:

    php artisan dd "User::first()->tap(fn($user) => dd($user->posts))"
    
  2. Debug Exceptions: Catch exceptions in the command line:

    php artisan dd "try { User::find(999); } catch (\Exception $e) { dd($e->getMessage()); }"
    
  3. Use with Laravel Sail: Debug containers directly:

    sail artisan dd "DB::connection()->getPdo()"
    
  4. 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())"
    
  5. Log Output to File: Redirect output for later analysis:

    php artisan dd "User::all()" > /tmp/debug_users.log
    
  6. Performance Profiling: Measure execution time:

    php artisan dd "User::all(); dd(microtime(true) - LARAVEL_START);"
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport