PHPackages                             timacdonald/pulse-validation-errors - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. timacdonald/pulse-validation-errors

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

timacdonald/pulse-validation-errors
===================================

Validation errors card for Laravel Pulse

v1.5.1(1y ago)105528.1k—1.6%6MITPHPPHP ^8.1

Since May 10Pushed 1y ago2 watchersCompare

[ Source](https://github.com/timacdonald/pulse-validation-errors)[ Packagist](https://packagist.org/packages/timacdonald/pulse-validation-errors)[ RSS](/packages/timacdonald-pulse-validation-errors/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (11)Used By (0)

Validation errors card for Laravel Pulse
========================================

[](#validation-errors-card-for-laravel-pulse)

A card for Laravel Pulse to show validation errors impacting users.

[![Validation errors card for Laravel Pulse](https://raw.githubusercontent.com/timacdonald/pulse-validation-errors/main/art/screenshot.png)](https://raw.githubusercontent.com/timacdonald/pulse-validation-errors/main/art/screenshot.png)

Installation
------------

[](#installation)

First, install the package via composer:

```
composer require timacdonald/pulse-validation-errors
```

Next, add the recorder to your `config/pulse.php`:

```
return [
    // ...

    'recorders' => [
        TiMacDonald\Pulse\Recorders\ValidationErrors::class => [
            'enabled' => env('PULSE_VALIDATION_ERRORS_ENABLED', true),
            'sample_rate' => env('PULSE_VALIDATION_ERRORS_SAMPLE_RATE', 1),
            'capture_messages' => true,
            'ignore' => [
                // '#^/login$#',
                // '#^/register$#',
                // '#^/forgot-password$#',
            ],
            'groups' => [
                // '#^/products/.*$#' => '/products/{user}',
            ],
        ],

        // ...
    ],
];
```

Next, add the card to your `resources/views/vendor/pulse/dashboard.php`:

```

```

Finally, get to improving your user experience. At LaraconUS I gave a [talk on how much our validation sucks](https://youtu.be/MMc2TzBY6l4?si=UEu8dLuRK4XT30yK). If you are here, you likely also care about how your users experience validation errors on your app, so I'd love you to give it a watch.

Features
--------

[](#features)

- Supports session based validation errors
- Supports API validation errors
- Support Inertia validation errors
- Support Livewire validation errors
- Supports multiple error bags
- Fallback for undetectable validation errors (based on 422 response status)
- Capture generic validation exceptions for custom response types

Ignore specific error messages
------------------------------

[](#ignore-specific-error-messages)

You may ignore specific endpoints via the recorders `ignore` key, however in some situations you may need more complex ignore rules. You can use [Pulse's built in `Pulse::filter` method](https://laravel.com/docs/11.x/pulse#filtering) to achieve this.

Here is an example where we are ignore a specific error message:

```
use Laravel\Pulse\Entry;
use Laravel\Pulse\Facades\Pulse;
use Laravel\Pulse\Value;

/**
 * Bootstrap any application services.
 */
public function boot(): void
{
    Pulse::filter(fn ($entry): bool => match ($entry->type) {
        'validation_error' => ! Str::contains($entry->key, [
            'The password is incorrect.',
            'Your password has appeared in a data leak.',
            // ...
        ]),
        // ...
        default => true,
    });
}
```

Capture validation errors for custom response formats
-----------------------------------------------------

[](#capture-validation-errors-for-custom-response-formats)

If you are returning custom response formats, you may see `__laravel_unknown` in the dashboard instead of the input names and error messages. This is because the package parses the response body to determine the validation errors. When the body is in an unrecognised format it is unable to parse the keys and messages from the response.

You should instead dispatch the `ValidationExceptionOccurred` event to pass the validation messages to the card's recorder. You may do this wherever you are converting your exceptions into responses. This usually happens in the `app/Exceptions/Handler`:

```
