public function validate(Model $model, $value)
    {
        if (!empty($this->choices) && !empty($value)) {
            foreach ($this->choices as $key => $choice) {
                if (is_array($choice)) {
                    foreach ($choice as $inkey => $inchoice) {
                        if ($value === $inchoice) {
                            return;
                        }
                    }
                } else {
                    if ($value === $choice) {
                        return;
                    }
                }
            }

            throw new ValidationError(
                sprintf('Value %s is not a valid choice.', $value),
                'invalid_choice'
            );
        }

        if (is_null($value) && !$this->isNull()) {
            throw new ValidationError('This field cannot be null.', 'null');
        }

        if (empty($value) && !$this->formBlank) {
            throw new ValidationError('This field cannot be blank.', 'blank');
        }
    }
public function validate(Model $model, $value)
    {
        if (!empty($this->choices) && !empty($value)) {
            foreach ($this->choices as $key => $choice) {
                if (is_array($choice)) {
                    foreach ($choice as $inkey => $inchoice) {
                        if ($value === $inchoice) {
                            return;
                        }
                    }
                } else {
                    if ($value === $choice) {
                        return;
                    }
                }
            }

            throw new ValidationError(
                sprintf('Value %s is not a valid choice.', $value),
                'invalid_choice'
            );
        }

        if (is_null($value) && !$this->isNull()) {
            throw new ValidationError('This field cannot be null.', 'null');
        }

        if (empty($value) && !$this->formBlank) {
            throw new ValidationError('This field cannot be blank.', 'blank');
        }
    }
public function validate ( Model $ model , $ value ) { if ( ! empty ( $ this -> choices ) && ! empty ( $ value ) ) { foreach ( $ this -> choices as $ key => $ choice ) { if ( is_array ( $ choice ) ) { foreach ( $ choice as $ inkey => $ inchoice ) { if ( $ value === $ inchoice ) { return ; } } } else { if ( $ value === $ choice ) { return ; } } } throw new ValidationError ( sprintf ( 'Value %s is not a valid choice.' , $ value ) , 'invalid_choice' ) ; } if ( is_null ( $ value ) && ! $ this -> isNull ( ) ) { throw new ValidationError ( 'This field cannot be null.' , 'null' ) ; } if ( empty ( $ value ) && ! $ this -> formBlank ) { throw new ValidationError ( 'This field cannot be blank.' , 'blank' ) ; } }
Validates value and throws ValidationError. Subclasses should override this to provide validation logic.

@param Model $model
@param       $value

@throws ValidationError
@author: Eddilbert Macharia (http://eddmash.com)<edd.cowan@gmail.com>
Validates value and throws ValidationError . Subclasses should override this to provide validation logic .