Improve the default output of
dd() in Laravel projects. Improves the default
dump behavior for many core Laravel objects, including:
- Query Builders
- Service Container
- Database Connections
- Carbon Instances
- Requests and Responses
Install as a dev dependency:
# composer require glhd/laravel-dumper --dev
dd() as you would normally, and enjoy the newly curated 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
You can see comparisons between the default
dd() output and the
in the diffs directory of this repository.
If there are objects in your project that you would like to customize the
for, you can register custom casters using the
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
reorder method accepts an array of patterns. For example, the default
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
By applying bespoke ordering rules, you can make sure that the properties you usually
need to debug are at the top of the
It's also possible to register your own casters for any class by publishing the
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.