Download the PHP package michaeljennings/validation without Composer

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

Validation Latest Stable Version Latest Unstable Version License

A laravel 4 validation package aiming to help you clean up your controllers and models, and make validation quicker and simpler.

Installation

Include the package in your composer.json.

  
"michaeljennings/validation": "1.0"
  

Run composer install or composer update to download the dependencies.

Once the package has been downloaded add the validation service provider to the list of service providers in app/config/app.php.

  
'providers' => array(

  'Michaeljennings\Validation\ValidationServiceProvider'

);
  

Add the Validation facade to your aliases array.

  
'aliases' => array(

  'Validation' => 'Michaeljennings\Validation\Facades\Validation',

);
  

Publish the config files using the php artisan config:publish michaeljennings/validation

By default the validators are store in a app/validators.php so you may need to create this file. Alternatively if you want to store your validators else where you can update the path in the package config.

Usage

Creating a Validator

To create a new validator we use the add function. This function takes two arguments, a name for the validator to be called by and a closure with the rules for the validator.

  
Validation::add('exampleValidator', function($validator)
{

  $validator->rule('name')->required();

});
  

To break this down the Validation::add('exampleValidator', function($validator) {}); adds a new validator into a collection with the name 'exampleValidator'.

We then add all of our validation rules on the $validator object. To create a new rule we use the rule function and then we can chain the laravel validation rules on the rule object.

For example if we wanted to validate an email field to make sure a value was passed and that the value was a valid email address we could use $validator->rule('email')->required()->email();.

The validation rules can either be camel cased or snake cased so both $validator->('foo')->requiredWith('bar'); and $validator->('foo')->required_with('bar'); are valid.

To see all of the available validation rules see the laravel docs.

Validation Error Messages

If you need to set a different validation error message we can use the message function. The message function takes two arguments, the validation rule the message is shown for and the error message.

  
$validator->rule('foo')->required()->message('required', 'This is a different validation message');
  

Using a Validator

To run a validator we use the make function. This function takes two arguments, the name of the validator we want to run and the input to be validated. When we call the make function the validator is bound to the validation class so we can call any of the laravel validation functions on the Validation facade.

  
Validation::make('exampleValidator', Input::all());

if (Validation::passes()) {
 // Handle success
} else {
  return Redirect::back()->withErrors(Validation::errors());
}
  

You can also chain functions when using the make function, for example:

  
if (Validation::make('exampleValidator', Input::all())->fails()) {
  return Redirect::back()->withErrors(Validation::errors());
}
  

If you need to add a rule to the validator after it has been made you can do so by using the rule function to create the new rules and then the createRules function to update the validators rules.

  
Validation::make('exampleValidator', Input::all());

Validation::rule('foo')->required();
Validation::createRules();
  

All versions of validation with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
illuminate/support Version 4.2.*
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 michaeljennings/validation contains the following files

Loading the files please wait ....