src/ResourceValidationsTrait.php
protected function validateAmong($field, $val, array $validOptions, $required = true)
    {
        if ($val !== null) {
            $result = in_array($val, $validOptions, true);
        } else {
            $result = !$required;
        }

        if ($result) {
            $this->clearError($field, 'validAmongOptions');
            return true;
        } else {
            $this->setError($field, 'validAmongOptions', [
                "title" => "Invalid Value for Field `$field`",
                "detail" => "Field `$field` must be one of the accepted options: `".implode("`, `", $validOptions)."`"
            ]);
            return false;
        }
    }
protected function validateAmong($field, $val, array $validOptions, $required = true)
    {
        if ($val !== null) {
            $result = in_array($val, $validOptions, true);
        } else {
            $result = !$required;
        }

        if ($result) {
            $this->clearError($field, 'validAmongOptions');
            return true;
        } else {
            $this->setError($field, 'validAmongOptions', [
                "title" => "Invalid Value for Field `$field`",
                "detail" => "Field `$field` must be one of the accepted options: `".implode("`, `", $validOptions)."`"
            ]);
            return false;
        }
    }
protected function validateAmong ( $ field , $ val , array $ validOptions , $ required = true ) { if ( $ val !== null ) { $ result = in_array ( $ val , $ validOptions , true ) ; } else { $ result = ! $ required ; } if ( $ result ) { $ this -> clearError ( $ field , 'validAmongOptions' ) ; return true ; } else { $ this -> setError ( $ field , 'validAmongOptions' , [ "title" => "Invalid Value for Field `$field`" , "detail" => "Field `$field` must be one of the accepted options: `" . implode ( "`, `" , $ validOptions ) . "`" ] ) ; return false ; } }
Validates that the value for a given field is in the given array of valid options

@param string $field The name of the field (attribute or relationship) being validated
@param mixed $val The value to validate
@param array $validOptions The collection of valid options among which the value should be found
@param bool $required Whether or not the value is required (this affects how `null` is handled)
@return bool Whether or not the validation has passed
Validates that the value for a given field is in the given array of valid options