[9.x] Add Laravel-specific casting to the var dumper #44408
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I created laravel-dumper as a standalone package for three reasons: 1) I wanted to prove the concept, 2) I was concerned about proposing Laravel maintain its own VarDumper implementation, and 3) I wasn't sure if it was too opinionated for core.
It's now a successful package with ~300 stars and over 100,000 installs, so I think the "prove the concept" phase is done. And now that the new
dd()
improvements have been merged, the maintenance commitment concern has been addressed. That just leaves the "too opinionated" concern.As a result, I've copied over much of the existing
laravel-dumper
implementation, but adjusted it in a few places to use more conservative defaults (and updated the implementation to match the existing Laravel core codebase).As of now, I have custom casts for:
HeaderBag
andParameterBag
objectsFor the most part, these casts just simplify the output and remove noise (most notably in objects that hold a reference to the service container). In a few cases, I've also reordered attributes so that the data you're most likely wanting to view is at the top, or added virtual properties for easier debugging (like a nicely formatted date/time string for carbon instances).
You can see a full list of before/after diffs in the original package repo (although some diffs may be slightly different in this implementation—especially Models).