Jump24 - Laravel Developers that Click into Place. Never outsourced. Never offshored. Always exceptional.

Laravel Dumper

glhd/laravel-dumper image

Laravel Dumper stats

Downloads
351K
Stars
310
Open Issues
1
Forks
7

View on GitHub →

Laravel Dumper

Improve the default output of dump() and dd() in Laravel projects. Improves the default dump behavior for many core Laravel objects, including:

  • Models
  • Query Builders
  • Service Container
  • Database Connections
  • Carbon Instances
  • Requests and Responses

https://user-images.githubusercontent.com/21592/150163719-547ecd90-b029-4588-9648-34891e5e0886.mp4

Installation

Install as a dev dependency:

# composer require glhd/laravel-dumper --dev

Usage

Just use dd() as you would normally, and enjoy the newly curated output!

Original Dump Output

If, for some reason, you really need the full debug output for an object that laravel-dumper customizes, you can do a "full" dump with ddf() and dumpf().

Comparison to Default Output

You can see comparisons between the default dd() output and the laravel-dumper output in the diffs directory of this repository.

Custom Casters

If there are objects in your project that you would like to customize the dd() behavior for, you can register custom casters using the CustomCaster class:

use Glhd\LaravelDumper\Casters\CustomCaster;
 
CustomCaster::for(User::class)
->only(['attributes', 'exists', 'wasRecentlyCreated']) // Props to keep (or use `except` to exclude)
->virtual('admin', fn(User $user) => $user->isAdmin()) // Add virtual props
->filter() // Filter out empty/null props (accepts callback)
->reorder(['attributes', 'admin', '*']); // Adjust the order of props

The reorder method accepts an array of patterns. For example, the default Model caster uses the following ordering rules:

$order = [
'id',
'*_id',
'*',
'*_at',
'created_at',
'updated_at',
'deleted_at',
];

This ensures that id is always first, followed by all foreign keys, followed by all other attributes, and then finally followed by timestamp attributes (with deleted_at last). By applying bespoke ordering rules, you can make sure that the properties you usually need to debug are at the top of the dd() output.

Advanced Custom Casters

It's also possible to register your own casters for any class by publishing the laravel-dumper config file and registering your custom classes in the 'casters' section of the config. This gives you the same level of control over the dd() output as the core Symfony VarDumper package, but is more complex to implement.

Your custom casters should extend Glhd\LaravelDumper\Casters\Caster and implement the cast method. See any of our built-in casters for more details.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Glhd Laravel Dumper Related Articles

Flux 2.0 Livewire UI Kit image

Flux 2.0 Livewire UI Kit

Read article
Whisper.php - Automatic speech recognition and transcription image

Whisper.php - Automatic speech recognition and transcription

Read article
Laravel 11 streamlined configuration files image

Laravel 11 streamlined configuration files

Read article
Setting up your Data Model in Laravel image

Setting up your Data Model in Laravel

Read article
API Integrations using Saloon in Laravel image

API Integrations using Saloon in Laravel

Read article
Blade Component Slot Attributes in Laravel 8.56 image

Blade Component Slot Attributes in Laravel 8.56

Read article
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing