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. Order new helper alphabetically :)
  • Loading branch information
Aden Fraser committed Dec 4, 2015
1 parent 6eca7b9 commit 2b05401
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 @@ -662,6 +663,28 @@ function url($path = null, $parameters = [], $secure = null)
}
}

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) {

This comment has been minimized.

Copy link
@ibrasho

ibrasho Dec 12, 2015

Contributor

This is never triggered since the first two parameters are mandatory.

return $factory;
}

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

if (! function_exists('view')) {
/**
* Get the evaluated view contents for the given view.
Expand Down

1 comment on commit 2b05401

@AdenFraser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats actually a really valid point!

Please sign in to comment.