Skip to main content

What is the Dumpable trait?

Illuminate\Support\Traits\Dumpable is a small trait that adds dump() and dd() to any class. It was introduced in Laravel 10 and is widely used to provide a consistent debugging experience across core APIs such as Collection, Eloquent Builder, and Request. The goal is simple: inspect an object quickly, and optionally stop execution at that exact point.

Check the implementation

The implementation is minimal. It only forwards to dump($this, ...$args) and dd($this, ...$args).
trait Dumpable
{
    public function dump(...$args): static
    {
        dump($this, ...$args);
        return $this;
    }

    public function dd(...$args): never
    {
        dd($this, ...$args);
    }
}
In Laravel 13, the source lives in src/Illuminate/Support/Traits/Dumpable.php. The runtime implementation expresses return behavior via PHPDoc (@return $this and @return never).

Add it to your own class

Add use Dumpable; and your class gets dump() / dd() as instance methods.
use Illuminate\Support\Traits\Dumpable;

class UserData
{
    use Dumpable;
    
    public function __construct(
        public readonly string $name,
        public readonly string $email,
    ) {}
}

$user = new UserData('Taro', '[email protected]');

$user->dump(); // dump and continue
$user->dd();   // dump and terminate

Debug in the middle of a fluent chain

dump() returns static (implemented as $this), so you can insert it safely in method chains.
$result = collect([1, 2, 3])
    ->map(fn ($n) => $n * 2)
    ->dump()  // inspect the intermediate value
    ->filter(fn ($n) => $n > 2)
    ->values();
If you switch to dd(), execution stops at that exact point, which is useful before expensive or side-effect-heavy steps.

Using it in package development

Adding Dumpable to your own Value Objects, DTOs, and Builder classes gives package users a built-in way to inspect internal state.
1

Add it to a Value Object / DTO

use Illuminate\Support\Traits\Dumpable;

final class InvoiceData
{
    use Dumpable;

    public function __construct(
        public readonly string $number,
        public readonly int $total,
    ) {}
}
2

Use it in a fluent builder chain

$payload = (new PackageRequestBuilder)
    ->forUser($userId)
    ->withLocale('en')
    ->dump('before send')
    ->toArray();

Passing extra arguments

Because Dumpable calls dump($this, ...$args) and dd($this, ...$args), you can pass contextual labels together with the object.
$user->dump('Debug point A');
// Dumps $this and 'Debug point A' together
This is useful when you have multiple dump points and need to identify each one immediately.

tap() helper / Tappable

Learn how to insert side effects while returning the original value.

The Conditionable trait

Learn conditional branching in fluent chains.

The Macroable trait

Learn how to extend existing classes with custom methods.
Last modified on May 24, 2026