当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::make方法代码示例

本文整理汇总了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;
 }
开发者ID:sarthak96agarwal,项目名称:quoterr.me,代码行数:13,代码来源:Model.php

示例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");
 }
开发者ID:jtrupina,项目名称:mobile-app-challenge-2015-web,代码行数:29,代码来源:AuthController.php

示例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;
 }
开发者ID:mannysoft,项目名称:database,代码行数:27,代码来源:Model.php

示例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;
 }
开发者ID:doberbeatz,项目名称:backend,代码行数:25,代码来源:Model.php

示例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;
     }
 }
开发者ID:pedronalbert,项目名称:lions-server,代码行数:11,代码来源:Member.php

示例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;
 }
开发者ID:waavi,项目名称:translation,代码行数:18,代码来源:LanguageRepository.php

示例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);
 }
开发者ID:vipervoid,项目名称:Pitimi,代码行数:21,代码来源:ValidationException.php

示例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']);
 }
开发者ID:heidilux,项目名称:Laravel-Company-Directory,代码行数:10,代码来源:AuthController.php

示例9: validate

 public static function validate($data)
 {
     $reglas = self::$rules;
     return Validator::make($data, $reglas);
 }
开发者ID:josimarjimenez,项目名称:architects,代码行数:5,代码来源:Material.php

示例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());
 }
开发者ID:olsgreen,项目名称:laravel-guardian,代码行数:10,代码来源:Guardian.php

示例11: validate

 public static function validate($data)
 {
     //$validate = new Validator(,array $data, static::$rules);
     return Validator::make($data, static::$rules);
 }
开发者ID:runningjack,项目名称:lexmark2,代码行数:5,代码来源:Branch.php

示例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;
 }
开发者ID:parfumix,项目名称:form-builder,代码行数:17,代码来源:Input.php


注:本文中的Illuminate\Validation\Validator::make方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。