PHP code example of timacdonald / pulse-validation-errors

1. Go to this page and download the library: Download timacdonald/pulse-validation-errors library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

timacdonald / pulse-validation-errors example snippets



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}',
            ],
        ],

        // ...
    ],
];

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,
    });
}



namespace App\Exceptions\Handler;

use Illuminate\Support\Facades\Event;
use Illuminate\Validation\ValidationException;
use Laravel\Pulse\Facades\Pulse;
use Throwable;
use TiMacDonald\Pulse\ValidationExceptionOccurred

class Handler
{
    // ...

    public function render($request, Throwable $e)
    {
        if ($e instanceof ValidationException) {
            Pulse::rescue(fn () => Event::dispatch(new ValidationExceptionOccurred($request, $e)));
        }

        // custom exception rendering logic...
    }
}