class Rule

Traits

Constants

UNDOTTED_DATA_CONTEXT_KEY

CoroutineContext key for caching the undotted data in Rule::compile().

Set by ValidationRuleParser::explodeWildcardRulesCompilable() to avoid repeated Arr::undot() calls when Rule::forEach expands wildcard items.

Properties

static protected array $macros

The registered string macros.

from  Macroable

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

static Can
can(string $ability, mixed ...$arguments)

Get a can constraint builder instance.

when(bool|callable $condition, array|Closure|InvokableRule|Rule|string|ValidationRule $rules, array|Closure|InvokableRule|Rule|string|ValidationRule $defaultRules = [])

Apply the given rules if the given condition is truthy.

unless(bool|callable $condition, array|Closure|InvokableRule|Rule|string|ValidationRule $rules, array|Closure|InvokableRule|Rule|string|ValidationRule $defaultRules = [])

Apply the given rules if the given condition is falsy.

static ArrayRule
array(mixed $keys = null)

Get an array rule builder instance.

static NestedRules
forEach(Closure $callback)

Create a new nested rule set.

static Unique
unique(string $table, string $column = 'NULL')

Get a unique constraint builder instance.

static Exists
exists(string $table, string $column = 'NULL')

Get an exists constraint builder instance.

static In
in(array|Arrayable|UnitEnum|string $values)

Get an in rule builder instance.

static NotIn
notIn(array|Arrayable|UnitEnum|string $values)

Get a not_in rule builder instance.

static Contains
contains(array|Arrayable|UnitEnum|string $values)

Get a contains rule builder instance.

static DoesntContain
doesntContain(array|Arrayable|UnitEnum|string $values)

Get a doesnt_contain rule builder instance.

static RequiredIf
requiredIf(bool|Closure|null $callback)

Get a required_if rule builder instance.

static RequiredUnless
requiredUnless(bool|Closure|null $callback)

Get a required_unless rule builder instance.

static ExcludeIf
excludeIf(bool|Closure $callback)

Get a exclude_if rule builder instance.

static ExcludeUnless
excludeUnless(bool|Closure $callback)

Get a exclude_unless rule builder instance.

static ProhibitedIf
prohibitedIf(bool|Closure $callback)

Get a prohibited_if rule builder instance.

prohibitedUnless(bool|Closure $callback)

Get a prohibited_unless rule builder instance.

static Date
date()

Get a date rule builder instance.

static Date
dateTime()

Get a datetime rule builder instance.

static Email
email()

Get an email rule builder instance.

static Enum
enum(string $type)

Get an enum rule builder instance.

static File
file()

Get a file rule builder instance.

static ImageFile
imageFile(bool $allowSvg = false)

Get an image file rule builder instance.

static Dimensions
dimensions(array $constraints = [])

Get a dimensions rule builder instance.

static StringRule
string()

Get a string rule builder instance.

static Numeric
numeric()

Get a numeric rule builder instance.

static AnyOf
anyOf(array $rules)

Get an "any of" rule builder instance.

static object
compile(string $attribute, mixed $rules, array|null $data = null)

Compile a set of rules for an attribute.

static void
flushState()

Flush all static state.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 56
static Can can(string $ability, mixed ...$arguments)

Get a can constraint builder instance.

Parameters

string $ability
mixed ...$arguments

Return Value

Can

at line 64
static ConditionalRules when(bool|callable $condition, array|Closure|InvokableRule|Rule|string|ValidationRule $rules, array|Closure|InvokableRule|Rule|string|ValidationRule $defaultRules = [])

Apply the given rules if the given condition is truthy.

Parameters

bool|callable $condition
array|Closure|InvokableRule|Rule|string|ValidationRule $rules
array|Closure|InvokableRule|Rule|string|ValidationRule $defaultRules

Return Value

ConditionalRules

at line 75
static ConditionalRules unless(bool|callable $condition, array|Closure|InvokableRule|Rule|string|ValidationRule $rules, array|Closure|InvokableRule|Rule|string|ValidationRule $defaultRules = [])

Apply the given rules if the given condition is falsy.

Parameters

bool|callable $condition
array|Closure|InvokableRule|Rule|string|ValidationRule $rules
array|Closure|InvokableRule|Rule|string|ValidationRule $defaultRules

Return Value

ConditionalRules

at line 86
static ArrayRule array(mixed $keys = null)

Get an array rule builder instance.

Parameters

mixed $keys

Return Value

ArrayRule

at line 94
static NestedRules forEach(Closure $callback)

Create a new nested rule set.

Parameters

Closure $callback

Return Value

NestedRules

at line 102
static Unique unique(string $table, string $column = 'NULL')

Get a unique constraint builder instance.

Parameters

string $table
string $column

Return Value

Unique

at line 110
static Exists exists(string $table, string $column = 'NULL')

Get an exists constraint builder instance.

Parameters

string $table
string $column

Return Value

Exists

at line 118
static In in(array|Arrayable|UnitEnum|string $values)

Get an in rule builder instance.

Parameters

array|Arrayable|UnitEnum|string $values

Return Value

In

at line 130
static NotIn notIn(array|Arrayable|UnitEnum|string $values)

Get a not_in rule builder instance.

Parameters

array|Arrayable|UnitEnum|string $values

Return Value

NotIn

at line 142
static Contains contains(array|Arrayable|UnitEnum|string $values)

Get a contains rule builder instance.

Parameters

array|Arrayable|UnitEnum|string $values

Return Value

Contains

at line 154
static DoesntContain doesntContain(array|Arrayable|UnitEnum|string $values)

Get a doesnt_contain rule builder instance.

Parameters

array|Arrayable|UnitEnum|string $values

Return Value

DoesntContain

at line 166
static RequiredIf requiredIf(bool|Closure|null $callback)

Get a required_if rule builder instance.

Parameters

bool|Closure|null $callback

Return Value

RequiredIf

at line 174
static RequiredUnless requiredUnless(bool|Closure|null $callback)

Get a required_unless rule builder instance.

Parameters

bool|Closure|null $callback

Return Value

RequiredUnless

at line 182
static ExcludeIf excludeIf(bool|Closure $callback)

Get a exclude_if rule builder instance.

Parameters

bool|Closure $callback

Return Value

ExcludeIf

at line 190
static ExcludeUnless excludeUnless(bool|Closure $callback)

Get a exclude_unless rule builder instance.

Parameters

bool|Closure $callback

Return Value

ExcludeUnless

at line 198
static ProhibitedIf prohibitedIf(bool|Closure $callback)

Get a prohibited_if rule builder instance.

Parameters

bool|Closure $callback

Return Value

ProhibitedIf

at line 206
static ProhibitedUnless prohibitedUnless(bool|Closure $callback)

Get a prohibited_unless rule builder instance.

Parameters

bool|Closure $callback

Return Value

ProhibitedUnless

at line 214
static Date date()

Get a date rule builder instance.

Return Value

Date

at line 222
static Date dateTime()

Get a datetime rule builder instance.

Return Value

Date

at line 230
static Email email()

Get an email rule builder instance.

Return Value

Email

at line 240
static Enum enum(string $type)

Get an enum rule builder instance.

Parameters

string $type

Return Value

Enum

at line 248
static File file()

Get a file rule builder instance.

Return Value

File

at line 256
static ImageFile imageFile(bool $allowSvg = false)

Get an image file rule builder instance.

Parameters

bool $allowSvg

Return Value

ImageFile

at line 264
static Dimensions dimensions(array $constraints = [])

Get a dimensions rule builder instance.

Parameters

array $constraints

Return Value

Dimensions

at line 272
static StringRule string()

Get a string rule builder instance.

Return Value

StringRule

at line 280
static Numeric numeric()

Get a numeric rule builder instance.

Return Value

Numeric

at line 290
static AnyOf anyOf(array $rules)

Get an "any of" rule builder instance.

Parameters

array $rules

Return Value

AnyOf

Exceptions

InvalidArgumentException

at line 298
static object compile(string $attribute, mixed $rules, array|null $data = null)

Compile a set of rules for an attribute.

Parameters

string $attribute
mixed $rules
array|null $data

Return Value

object

at line 329
static void flushState()

Flush all static state.

Return Value

void