PHPackages                             tzurbaev/laravel-extra-fields-validator - 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. tzurbaev/laravel-extra-fields-validator

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

tzurbaev/laravel-extra-fields-validator
=======================================

Extra fields validator for Laravel.

1.0.4(4y ago)01.7kMITPHPPHP ^7.4|^8.0

Since Jan 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/tzurbaev/laravel-extra-fields-validator)[ Packagist](https://packagist.org/packages/tzurbaev/laravel-extra-fields-validator)[ RSS](/packages/tzurbaev-laravel-extra-fields-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Laravel Extra Fields Validator
==============================

[](#laravel-extra-fields-validator)

[![GitHub Workflow Status](https://camo.githubusercontent.com/f53486bae41a223f3de0f1ed38960467b87a2fdd8be2746c770717febb7f7b7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f747a7572626165762f6c61726176656c2d65787472612d6669656c64732d76616c696461746f722f746573743f6c6162656c3d5465737473)](https://camo.githubusercontent.com/f53486bae41a223f3de0f1ed38960467b87a2fdd8be2746c770717febb7f7b7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f747a7572626165762f6c61726176656c2d65787472612d6669656c64732d76616c696461746f722f746573743f6c6162656c3d5465737473)[![StyleCI](https://camo.githubusercontent.com/66a6c3cb3bdb7b3c201c68c967023783b09733059564455412ac519f2ef5c8a8/68747470733a2f2f7374796c6563692e696f2f7265706f732f3233353531333039372f736869656c643f6272616e63683d6d6173746572267374796c653d666c6174)](https://styleci.io/repos/235513097)[![ScrutinizerCI](https://camo.githubusercontent.com/dd5d61f521de5a231752924243a0aeae21f466eecf603a1eb14896a4bcc6ebb8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747a7572626165762f6c61726176656c2d65787472612d6669656c64732d76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tzurbaev/laravel-extra-fields-validator/)[![Latest Version on Packagist](https://camo.githubusercontent.com/2d6bbf963fb326bddbb9b1948b3746b8d729561408933d3a51192c40ee996fc5/68747470733a2f2f706f7365722e707567782e6f72672f747a7572626165762f6c61726176656c2d65787472612d6669656c64732d76616c696461746f722f76657273696f6e3f666f726d61743d666c6174)](https://packagist.org/packages/tzurbaev/laravel-extra-fields-validator)[![Software License](https://camo.githubusercontent.com/b05bd437d5cd57f8e28a9f0b89ddf893e869d80b2d4cd31ba72bcff64eab7cf6/68747470733a2f2f706f7365722e707567782e6f72672f747a7572626165762f6c61726176656c2d65787472612d6669656c64732d76616c696461746f722f6c6963656e73653f666f726d61743d666c6174)](LICENSE.md)

Description
-----------

[](#description)

This package allows to perform validation of exta (redundant) fields that were sent with HTTP request.

All you need to do is create new [Form Request](https://laravel.com/docs/6.x/validation#form-request-validation)by extending `Laravel\ExtraFieldsValidator\ExtraFormRequest` class (instead of `Illuminate\Foundation\Http\FormRequest`).

Since the `ExtraFormRequest` extends the original `FormRequest` class, you can work with this class just as with regular Form Request.

Behind the scenes `ExtraFormRequest` creates custom instance of Validator class (`Laravel\ExtraFieldsValidator\Validator`) that allows to register &amp; run extra callbacks (after successful validation &amp; after failed validation).

After successful validation `ExtraFormRequest` will try to find fields that are not described in `rules` list but present in actual HTTP request payload.

If there's any, response will finish with `HTTP 422 Unprocessable Entity` response and custom error message will be added to errors bag (`ExtraFormRequest::getExtraFieldErrorMessage(string $field): string`).

Requirements
------------

[](#requirements)

This package requires PHP 7.4 or higher.

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

[](#installation)

You can install the package via composer:

```
$ composer require tzurbaev/laravel-extra-fields-validator
```

Also you can publish package configuration:

```
php artisan vendor:publish --provider="Laravel\ExtraFieldsValidator\ExtraFieldsValidatorServiceProvider"
```

Usage
-----

[](#usage)

Let's say you have the following request:

```
