Skip to content

Commit

Permalink
Add a validator() helper as a shorthand for Validate::make()
Browse files Browse the repository at this point in the history
and use ::class notation
  • Loading branch information
AdenFraser authored and Aden Fraser committed Dec 3, 2015
1 parent 1cc5eeb commit 21bd68a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Illuminate/Foundation/helpers.php
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;

if (! function_exists('abort')) {
/**
Expand Down Expand Up @@ -682,3 +683,25 @@ function view($view = null, $data = [], $mergeData = [])
return $factory->make($view, $data, $mergeData);
}
}

if (! function_exists('validator')) {
/**
* Create a new Validator instance.
*
* @param array $data
* @param array $rules
* @param array $messages
* @param array $customAttributes
* @return \Illuminate\Contracts\Validation\Validator
*/
function validator(array $data, array $rules, array $messages = [], array $customAttributes = [])
{
$factory = app(ValidationFactory::class);

if (func_num_args() === 0) {
return $factory;
}

return $factory->make($data, $rules, $messages, $customAttributes);
}
}

0 comments on commit 21bd68a

Please sign in to comment.