Download the PHP package tzurbaev/laravel-extra-fields-validator without Composer

On this page you can find all versions of the php package tzurbaev/laravel-extra-fields-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-extra-fields-validator

Laravel Extra Fields Validator

GitHub Workflow Status StyleCI ScrutinizerCI Latest Version on Packagist

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 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 & run extra callbacks (after successful validation & 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

This package requires PHP 7.4 or higher.

Installation

You can install the package via composer:

Also you can publish package configuration:

Usage

Let's say you have the following request:

If actual HTTP request payload contains any other field, validation will fail.

Using custom validator

If you're creating custom validator via FormRequest's validator method, you need to use result of parent::validator() method as your base validator.

Using custom form request

If you're using custom FormRequest class and can't extend from ExtraFormRequest, you can include Laravel\ExtraFieldsValidator\ProvidesExtraFieldsValidator trait into your base/child class.

Error message

You need to add message to your validation.php language file (under the custom.extra_field path). The extra field name will be passed as :attribute replacement.

You can also override ExtraFormRequest::getExtraFieldErrorMessage method and return any custom message.

Data source

By default validator uses Laravel's FormRequest::validationData() method to retrieve data that should be validated. If you have request with no validation rules or your route can accept optional query params, this might lead to unexpected validation errors, since optional query params might be missing from your rules array.

You have 2 options to deal with this:

  1. Describe optional params in your rules method. This will not break your requests with optional query params but if there's any other non-described param, you will face validation exception;
  2. Change the extra-validator.data_source (or ENV variable EXTRA_VALIDATOR_DATA_SOURCE) value from default to input_source. This will instruct validator only to use JSON/Request data without query params.

GET requests

In most cases you should not use ExtraFormRequest for your GET routes. If you really need it, describe all available params in your rules method.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Testing

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-extra-fields-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tzurbaev/laravel-extra-fields-validator contains the following files

Loading the files please wait ....