Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

The new Dumpable trait in Laravel 11

The release of Laravel 11 is around the corner and it’s packed with a lot of new features and improvements. One of the new features that it brings is the new Dumpable trait.

The Illuminate\Support\Traits\Dumpable trait is a new trait that’s being introduced in Laravel 11. The trait provides dd and dump methods to the class where it’s being used.

This is particularly useful when you want to fluently call the dd or dump method directly on the object without having to use the dump/dd helper functions.

Here’s how you can use it.

use Illuminate\Support\Traits\Dumpable;

class User
{
    use Dumpable;

    public function __construct()
    {
        $this->name = 'Amit';
    }

    public function getName()
    {
        return $this->name;
    }
}

$user = new User;

$user->getName()->dump();
$user->getName()->dd();

As you may presume, the main benefit this trait will bring is that the Laravel package authors can now leverage this trait to provide a better debugging experience to the users of their packages. This will also make the debugging process more convenient and intuitive.

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?