Exemplo n.º 1
0
 /**
  * Get the validator instance for the request.
  *
  * @return \Illuminate\Validation\Validator
  */
 protected function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->addImplicitExtension('votes', function ($attribute, $value, $parameters) {
         if ($this->poll->is_multiple) {
             if (!is_array($value)) {
                 return false;
             }
             foreach ($value as $v) {
                 if (!is_numeric($v) || $v < 1 || $v > $this->poll->num_options()) {
                     return false;
                 }
             }
         } else {
             if (is_array($value)) {
                 return false;
             }
             if (!is_numeric($value) || $value < 1 || $value > $this->poll->num_options()) {
                 return false;
             }
         }
         return true;
     });
     $validator->addImplicitExtension('votes_maxOptions', function ($attribute, $value, $parameters) {
         if ($this->poll->max_options) {
             if (count($value) > $this->poll->max_options) {
                 return false;
             }
         }
         return true;
     });
     return $validator;
 }
Exemplo n.º 2
0
 /**
  * Get the validator instance for the request.
  *
  * @return \Illuminate\Validation\Validator
  */
 protected function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->addImplicitExtension('option', function ($attribute, $value, $parameters) {
         foreach ($value as $option) {
             if (!is_scalar($option)) {
                 return false;
             }
         }
         return true;
     });
     return $validator;
 }
Exemplo n.º 3
0
 /**
  * Get the validator instance for the request.
  *
  * @return \Illuminate\Validation\Validator
  */
 protected function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->addImplicitExtension('usernameArray', function ($attribute, $value, $parameters) {
         try {
             $this->getUseridArray($attribute);
         } catch (\Exception $e) {
             return false;
         }
         return true;
     });
     return $validator;
 }