class Enum implements Rule, ValidatorAwareRule, Stringable (View source)

Traits

Properties

protected UnitEnum> $type

The type of the enum.

protected Validator $validator

The current validator instance.

protected array $only

The cases that should be considered valid.

protected array $except

The cases that should be considered invalid.

Methods

$this|TWhenReturnType
when(TWhenParameter|TWhenParameter|null $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless(TUnlessParameter|TUnlessParameter|null $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

__construct(UnitEnum> $type)

Create a new rule instance.

bool
passes(string $attribute, mixed $value)

Determine if the validation rule passes.

$this
only(UnitEnum[]|UnitEnum|UnitEnum> $values)

Specify the cases that should be considered valid.

$this
except(UnitEnum[]|UnitEnum|UnitEnum> $values)

Specify the cases that should be considered invalid.

bool
isDesirable(mixed $value)

Determine if the given case is a valid case based on the only / except values.

string|array
message()

Get the validation error message.

$this
setValidator(Validator $validator)

Set the current validator.

string
__toString()

Convert the rule to a validation string.

Details

$this|TWhenReturnType when(TWhenParameter|TWhenParameter|null $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

TWhenParameter|TWhenParameter|null $value
callable|null $callback
callable|null $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless(TUnlessParameter|TUnlessParameter|null $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

TUnlessParameter|TUnlessParameter|null $value
callable|null $callback
callable|null $default

Return Value

$this|TUnlessReturnType

__construct(UnitEnum> $type)

Create a new rule instance.

Parameters

UnitEnum> $type

bool passes(string $attribute, mixed $value)

Determine if the validation rule passes.

Parameters

string $attribute
mixed $value

Return Value

bool

$this only(UnitEnum[]|UnitEnum|UnitEnum> $values)

Specify the cases that should be considered valid.

Parameters

UnitEnum[]|UnitEnum|UnitEnum> $values

Return Value

$this

$this except(UnitEnum[]|UnitEnum|UnitEnum> $values)

Specify the cases that should be considered invalid.

Parameters

UnitEnum[]|UnitEnum|UnitEnum> $values

Return Value

$this

protected bool isDesirable(mixed $value)

Determine if the given case is a valid case based on the only / except values.

Parameters

mixed $value

Return Value

bool

string|array message()

Get the validation error message.

Return Value

string|array

$this setValidator(Validator $validator)

Set the current validator.

Parameters

Validator $validator

Return Value

$this

string __toString()

Convert the rule to a validation string.

Return Value

string

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.