Skip to content

Validation Rule Constants #436

Description

@SmolSoftBoi

This might just be me being clumsy, but I've had a few instances of incorrectly setting validation rules (typos, etc…), what about having rule constant strings?

For example:

class Rules
{
    const REQUIRED = 'required';
    const IS_NATURAL_NO_ZERO = 'is_natural_no_zero';
}

$rules = [
    'id' => implode('|', [Rules::REQUIRED, RULES::IS_NATURAL_NO_ZERO])
];

Could even add a convenience method to the validation class:

class Validation
{
    public static function concatRules(string ...$rules): string
    {
        return implode('|', $rules);
    }
}

$rules = [
    'id' => Validation::concatRules([Rules::REQUIRED, Rules::IS_NATURAL_NO_ZERO])
];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions