• Stars
    star
    387
  • Rank 110,623 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Upgrade dd() with Laravel-specific improvements

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
laravel-dumper.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.

More Repositories

1

aire

Modern form builder for Laravel
PHP
535
star
2

gretel

Laravel breadcrumbs right out of a fairy tale
PHP
221
star
3

alpine-wizard

Multi-step wizard helpers for Alpine.js
JavaScript
145
star
4

conveyor-belt

All the underlying mechanics necessary to write artisan commands that process lots of data efficiently
PHP
133
star
5

tailwindcss-plugins

Plugins & helpers for tailwindcss
JavaScript
85
star
6

bits

PHP
73
star
7

dawn

Experimental next-gen browser testing for Laravel
PHP
72
star
8

laravel-addressing

Laravel package providing addressing functionality
PHP
62
star
9

linen

Lightweight spreadsheets for Laravel
PHP
50
star
10

special

PHP
17
star
11

hooks

PHP
14
star
12

tinker-gui

Laravel Tinker GUI
TypeScript
12
star
13

linearavel

PHP
9
star
14

laravel-timezone-mapper

Map latitude/longitude to a timezone without making external API calls
PHP
6
star
15

wp-bootstrap-widgets

Bootstrap Components as WordPress Widgets
PHP
6
star
16

aire-bootstrap

Bootstrap theme for Aire
PHP
6
star
17

laravel-dusk-browserstack

Easily run Laravel Dusk tests on BrowserStack
PHP
6
star
18

ansipants

PHP
6
star
19

laralint

Framework for linting Laravel projects
PHP
6
star
20

laravel-package-template

Template for Laravel packages
PHP
4
star
21

laravel-prismoquent

Prismoquent lets you access Prismic.io using the same methods you're used to in Eloquent.
PHP
2
star
22

medusa

Headless content management
JavaScript
2
star
23

ansible-interactive

Interactive CLI for ansible plays
JavaScript
2
star
24

fs-of-holding

A filesystem that has every file in it
PHP
1
star
25

aire-livewire

1
star
26

omniponent

JavaScript
1
star
27

suspend

PHP
1
star
28

aire-docs

Blade
1
star
29

vbulletin-bbcode-parser

Parser package for vBulletin bbCode
PHP
1
star
30

verbs-github-webhooks

A collection of Verbs events to use with GitHub webhooks
PHP
1
star
31

accounts-payable

Help collect tax documents and pay independent contractors
PHP
1
star