本文整理汇总了PHP中Illuminate\Validation\Validator::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::make方法的具体用法?PHP Validator::make怎么用?PHP Validator::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Validator
的用法示例。
在下文中一共展示了Validator::make方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validates current attributes against rules
*/
public function validate()
{
static::fireModelEvent('validating');
$v = $this->validator->make($this->attributes, $this->fixRules(static::$rules), static::$messages);
if ($v->passes()) {
return true;
}
$this->setErrors($v->messages());
return false;
}
示例2: register
/**
* API register
* @param Request $request
*/
public function register(Request $request)
{
$input = $request->all();
$rules = ['name' => 'required|max:60', 'email' => 'required|unique:users,email|email|max:40', 'password' => 'required|max:20', 'city' => 'required|max:30', 'country' => 'required|max:30', 'gender' => 'required|max:30', 'birth_date' => 'required|date_format:Y-m-d'];
$messages = ['required' => 'The :attribute field is required.', 'email.email' => 'Wrong email format', 'name.unique' => 'Given name is not unique', 'birth_date.date_format' => 'Date not in correct format'];
$validator = Validator::make($input, $rules, $messages);
if ($validator->fails()) {
$messages = $validator->errors();
$return_msg = array();
foreach ($messages->all() as $message) {
array_push($return_msg, $message);
}
return $return_msg;
}
$user = new User();
$user->name = $request->input('name');
$user->email = $request->input('email');
$user->password = bcrypt($request->input('password'));
$user->city = $request->input('city');
$user->country = $request->input('country');
$user->gender = $request->input('gender');
$user->birth_date = date('Y-m-d', strtotime($request->input('birth_date')));
$user->save();
return json_encode("success");
}
示例3: validate
public function validate()
{
$rules = self::processRules(static::$insertRules);
// Lets see if the key has value
if ($this->getKey() != NULL) {
// Lets use the update rules
$rules = self::processRules(static::$updateRules);
}
// Lets check if we have custom rules
if (isset($this->customRule)) {
$rule = 'customRule' . $this->customRule;
$rules = self::processRules(static::${$rule});
}
$messages = static::$messages;
// Well lets check if we have custom messages also
if (isset($this->customMessage)) {
$message = 'customMessage' . $this->customMessage;
$messages = static::${$message};
}
$validation = Validator::make($this->attributes, $rules, $messages);
if ($validation->passes()) {
return true;
}
$this->errors = $validation->messages()->all();
$this->validation = $validation;
return false;
}
示例4: validate
/**
* Validates current attributes against rules
* @param array $rules
*
* @return boolean
*/
public function validate($rules = array())
{
if (sizeof($rules) == 0) {
$rules = static::$rules;
}
$replace = $this->getKey() > 0 ? $this->getKey() : '';
foreach ($rules as $key => $rule) {
$rules[$key] = str_replace(':id', $replace, $rule);
}
/**
* @var \Illuminate\Validation\Validator $v
*/
$v = $this->validator->make($this->attributes, $rules, static::$messages);
if ($v->passes()) {
return true;
}
$this->setErrors($v->messages());
return false;
}
示例5: validate
public function validate($data)
{
$validatorRules = ['first_name' => 'required', 'last_name' => 'required', 'ci' => 'required|unique:members'];
$validator = Validator::make($data, $validatorRules, $validatorMessages);
if ($validator->fails()) {
$this->errors = $validator->errors()->all();
return false;
} else {
return true;
}
}
示例6: validate
/**
* Validate the given attributes
*
* @param array $attributes
* @return boolean
*/
public function validate(array $attributes)
{
$id = array_get($attributes, 'id', 'NULL');
$table = $this->model->getTable();
$rules = ['locale' => "required|unique:{$table},locale,{$id}", 'name' => "required|unique:{$table},name,{$id}"];
$validator = $this->validator->make($attributes, $rules);
if ($validator->fails()) {
$this->errors = $validator->errors();
return false;
}
return true;
}
示例7: __construct
/**
* Construct a new ValidationException.
* @param Illuminate\Support\Facades\Validator $validator The validator instance.
* @param string $field An optional field id.
* @param string $key An optional key message.
*/
public function __construct($validator, $field = null, $error = null)
{
if ($validator instanceof Validator) {
$this->validator = $validator;
} else {
$this->validator = Validator::make(array(), array());
}
if (is_string($field) && is_string($error)) {
$this->validator->getMessageBag()->add($field, trans("validation.{$error}"));
}
// Create message.
$messages = $this->validator->messages()->all();
$message = join(', ', $messages);
parent::__construct($message);
}
示例8: validator
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, ['username' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6']);
}
示例9: validate
public static function validate($data)
{
$reglas = self::$rules;
return Validator::make($data, $reglas);
}
示例10: getValidator
/**
* Returns a validator instance that
* will be used to validate the model.
*
* @return Illuminate\Validation\Validator
*/
public function getValidator()
{
return Validator::make($this->attributes, array());
}
示例11: validate
public static function validate($data)
{
//$validate = new Validator(,array $data, static::$rules);
return Validator::make($data, static::$rules);
}
示例12: isValid
/**
* Is valid element
*
* @return bool
*/
public function isValid()
{
if (!$this->hasRules()) {
return true;
}
return;
$this->validator = Validator::make($this->getAttribute('value'), $this->rules);
if ($this->validator->fails()) {
return false;
}
return true;
}