Download the PHP package anlutro/l4-validation without Composer

On this page you can find all versions of the php package anlutro/l4-validation. 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 l4-validation

Laravel 4 Validation Build Status Latest Version

Installation: composer require anlutro/l4-validation

Pick the latest stable version from packagist or the GitHub tag list.

WARNING: Backwards compatibility is not guaranteed during version 0.x.

Validation service

This validation class is a layer on top of Laravel's own Validation class (the one you create by calling Validator::make), meant to be injected into a repository or controller. It allows for more advanced rulesets and more dynamic rules, and is being utilized in my repository class.

Your class must implement one abstract method: getCommonRules. This should return an array of rules that are used on every validation call and should be the bare minimum of rules. In addition you can implement as many extra rule getters as you like - getCreateRules, getUpdateRules, getUpdateAsAdminRules, getFooRules and so on.

Rules are dynamically merged depending on what action you're trying to validate. For example, $validator->validCreate($attributes) will merge getCommonRules and getCreateRules. If getCreateRules doesn't exist, it'll just use getCommonRules. $validator->validUpdateAsAdmin($attributes) will merge getCommonRules and getUpdateAsAdminRules. Rules are merged recursively.

You can tell the validator to replace variables in rules with the replace($key, $value) method. For example, if you have a unique rule and want to dynamically replace the table with a model's table, you can do the following:

public function getCommonRules() {
    return ['email' => 'unique:<table>'];
}

$validator->replace('table', $model->getTable());

The class will also replace variables in square brackets with the matching key from input. For example, [foo] will be replaced with whatever the value of 'foo' from the provided input (attributes) are. This way, you can add the value of another input field to a rule (for example, 'end_date' => ['date', 'after:[start_date]'].

Replacing variables will not work in regex rules, as that would potentially break regex operators.

There are a couple of hooks you can use to add custom behaviour. prepareRules($rules, $attributes) will be called after rules are merged and allows you to change validation rules based on input if necessary. This method needs to return the modified array of rules!

prepareValidator($validator) is called before checking if validation passes or not, and can be used to add sometimes() rules or any other custom behaviour onto the Illuminate\Validation\Validator object itself.

Exceptions

You can call $validatorService->toggleExceptions(); to make the validator throw exceptions instead of just returning false. The exception thrown will be of the type anlutro\LaravelValidation\ValidationException, which has some useful methods.

It can also be cast to a string via (string) $exception which will render each validation error on one line.

Contact

Open an issue on GitHub if you have any problems or suggestions.

License

The contents of this repository is released under the MIT license.


All versions of l4-validation with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/validation Version >=4.1, <6.0
illuminate/support Version >=4.1, <6.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 anlutro/l4-validation contains the following files

Loading the files please wait ....