PHPackages                             kdabrow/validation-codes - 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. [API Development](/categories/api)
4. /
5. kdabrow/validation-codes

ActivePackage[API Development](/categories/api)

kdabrow/validation-codes
========================

Validation codes for API

v4.0.0(2mo ago)82.1k↑264.3%MITPHPPHP &gt;=8.3.0CI passing

Since Jun 3Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/karoldabro/validation-codes)[ Packagist](https://packagist.org/packages/kdabrow/validation-codes)[ RSS](/packages/kdabrow-validation-codes/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (6)Versions (8)Used By (0)

[![GitHub Workflow Status (branch)](https://github.com/karoldabro/validation-codes/actions/workflows/laravel.yml/badge.svg)](https://github.com/karoldabro/validation-codes/actions/workflows/laravel.yml/badge.svg)[![Packagist Version](https://camo.githubusercontent.com/41c4ec4cae2dfcaafb951ac7805f3e44139e528d1e6ea54c7613f04655215abe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b646162726f772f76616c69646174696f6e2d636f646573)](https://camo.githubusercontent.com/41c4ec4cae2dfcaafb951ac7805f3e44139e528d1e6ea54c7613f04655215abe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b646162726f772f76616c69646174696f6e2d636f646573)[![Packagist Downloads](https://camo.githubusercontent.com/884cdc4387ee25c4d3827eaa7baac41e79f8d756a6e2e30e17ebed6004514e26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6b646162726f772f76616c69646174696f6e2d636f646573)](https://camo.githubusercontent.com/884cdc4387ee25c4d3827eaa7baac41e79f8d756a6e2e30e17ebed6004514e26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6b646162726f772f76616c69646174696f6e2d636f646573)[![Scrutinizer code quality (GitHub/Bitbucket)](https://camo.githubusercontent.com/8c29c38bff8218c252d82142f5b4266f2858a39c4908c97e0dc3a2c914b2e7ea/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6b61726f6c646162726f2f76616c69646174696f6e2d636f6465732f6d6173746572)](https://camo.githubusercontent.com/8c29c38bff8218c252d82142f5b4266f2858a39c4908c97e0dc3a2c914b2e7ea/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6b61726f6c646162726f2f76616c69646174696f6e2d636f6465732f6d6173746572)

Validation Codes for Laravel
============================

[](#validation-codes-for-laravel)

This package enhances Laravel's validation error responses (status 422) by adding corresponding validation rule codes. After installation, the response format is as follows:

```
{
  "message": "validation errors",
  "errors": {
    "user_id": [
      "Field user_id is required"
    ]
  },
  "codes": {
    "user_id": [
      "E104"
    ]
  }
}
```

Error codes allow clients of your API to easily interpret returned validation errors in the way they want or need.

Sponsored by [Givore](https://givore.com) and [Mistflare](https://mistflare.studio)

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

[](#installation)

First, install the package using Composer:

PHPLaravelPackageCommand^8.3134.0`composer require "kdabrow/validation-codes: ^4.0"`^8.3123.0`composer require "kdabrow/validation-codes: ^3.0"`^8.2112.0`composer require "kdabrow/validation-codes: ^2.0"`^8.110[1.1](https://github.com/karoldabro/validation-codes/tree/v1.1.0)`composer require "kdabrow/validation-codes: ^1.1" `How It Works
------------

[](#how-it-works)

This package extends Laravel's default validation system by overwriting the default Handler to return the correct JSON response.

Configuration
-------------

[](#configuration)

### Overwriting Validation Codes

[](#overwriting-validation-codes)

To publish the configuration and language files containing the codes, use Laravel's command:

```
php artisan vendor:publish --tag=validation_codes
```

You can then change the validation codes corresponding to the given rules in the published file, which looks like this:

```
