Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Add a validator helper as a shorthand for Validate::make() #11146

Merged
merged 1 commit into from Dec 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
return $factory;
}

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

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