> For the complete documentation index, see [llms.txt](https://devsb.gitbook.io/laranotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devsb.gitbook.io/laranotes/usefull-packages/dumper.md).

# Dumper

[![Build Status](https://github.com/glhd/laravel-dumper/workflows/PHPUnit/badge.svg) ](https://github.com/glhd/laravel-dumper/actions)[![Coverage Status](https://api.codeclimate.com/v1/badges/f597a6e8d9f968a55f03/test_coverage) ](https://codeclimate.com/github/glhd/laravel-dumper/test_coverage)[![Latest Stable Release](https://poser.pugx.org/glhd/laravel-dumper/v/stable) ](https://packagist.org/packages/glhd/laravel-dumper)![MIT Licensed](https://poser.pugx.org/glhd/laravel-dumper/license) [![Follow @inxilpro on Twitter](https://img.shields.io/twitter/follow/inxilpro?style=social)](https://twitter.com/inxilpro)

## 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:

```shell
# composer require glhd/laravel-dumper --dev
```

### Usage

Just use `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 `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:

```php
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:

```php
$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.

## Learn More

{% embed url="<https://github.com/glhd/laravel-dumper/blob/main/README.md>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://devsb.gitbook.io/laranotes/usefull-packages/dumper.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
