class Rule (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable

Methods

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

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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(callable|bool $condition, ValidationRule|InvokableRule|Rule|Closure|Stringable|array|string $rules, ValidationRule|InvokableRule|Rule|Closure|Stringable|array|string $defaultRules = [])

Apply the given rules if the given condition is truthy.

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

Apply the given rules if the given condition is falsy.

static ArrayRule
array(array|null $keys = null)

Get an array rule builder instance.

static ArrayKeys
arrayKeys(Arrayable|array|string $keys)

Get an array keys rule builder instance.

static NestedRules
forEach(callable $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(Arrayable|UnitEnum|array|string $values)

Get an in rule builder instance.

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

Get a not_in rule builder instance.

static string
accepted()

Get an accepted validation rule.

static string
activeUrl()

Get an active_url validation rule.

static string
base64()

Get a base64 validation rule.

static string
bail()

Get a bail validation rule.

static string
boolean(bool $strict = false)

Get a boolean validation rule.

static string
declined()

Get a declined validation rule.

static string
exclude()

Get an exclude validation rule.

static string
filled()

Get a filled validation rule.

static string
hexColor()

Get a hex_color validation rule.

static string
json()

Get a json validation rule.

static ListRule
list()

Get a list validation rule.

static string
macAddress()

Get a mac_address validation rule.

static string
missing()

Get a missing validation rule.

static string
nullable()

Get a nullable validation rule.

static string
present()

Get a present validation rule.

static string
prohibited()

Get a prohibited validation rule.

static string
required()

Get a required validation rule.

static string
sometimes()

Get a sometimes validation rule.

static string
ulid()

Get an ulid validation rule.

static AcceptedIf
acceptedIf(string $anotherField, string|int|float|bool|null|array $value)

Get an accepted_if rule builder instance.

static DeclinedIf
declinedIf(string $anotherField, string|int|float|bool|null|array $value)

Get a declined_if rule builder instance.

static MissingIf
missingIf(string $anotherField, string|int|float|bool|null|array $value)

Get a missing_if rule builder instance.

static MissingUnless
missingUnless(string $anotherField, string|int|float|bool|null|array $value)

Get a missing_unless rule builder instance.

static PresentIf
presentIf(string $anotherField, string|int|float|bool|null|array $value)

Get a present_if rule builder instance.

static PresentUnless
presentUnless(string $anotherField, string|int|float|bool|null|array $value)

Get a present_unless rule builder instance.

static Confirmed
confirmed()

Get a confirmed rule builder instance.

static CurrentPassword
currentPassword()

Get a current_password rule builder instance.

static Distinct
distinct()

Get a distinct rule builder instance.

static ExcludeWith
excludeWith(string $anotherField)

Get an exclude_with rule builder instance.

static ExcludeWithout
excludeWithout(array|string $anotherField)

Get an exclude_without rule builder instance.

static InArray
inArray(string $otherField)

Get an in_array rule builder instance.

static InArrayKeys
inArrayKeys(array|string $keys)

Get an in_array_keys rule builder instance.

static IpAddress
ip()

Get an IP address rule builder instance.

static MissingWith
missingWith(array|string $fields)

Get a missing_with rule builder instance.

static MissingWithAll
missingWithAll(array|string $fields)

Get a missing_with_all rule builder instance.

static PresentWith
presentWith(array|string $fields)

Get a present_with rule builder instance.

static PresentWithAll
presentWithAll(array|string $fields)

Get a present_with_all rule builder instance.

prohibitedIfAccepted(string $field)

Get a prohibited_if_accepted rule builder instance.

prohibitedIfDeclined(string $field)

Get a prohibited_if_declined rule builder instance.

static Prohibits
prohibits(array|string $fields)

Get a prohibits rule builder instance.

static Regex
regex(string $pattern)

Get a regex rule builder instance.

static NotRegex
notRegex(string $pattern)

Get a not_regex rule builder instance.

requiredArrayKeys(array|string $keys)

Get a required_array_keys rule builder instance.

requiredIfAccepted(string $field)

Get a required_if_accepted rule builder instance.

requiredIfDeclined(string $field)

Get a required_if_declined rule builder instance.

static RequiredWith
requiredWith(array|string $fields)

Get a required_with rule builder instance.

static RequiredWithAll
requiredWithAll(array|string $fields)

Get a required_with_all rule builder instance.

static RequiredWithout
requiredWithout(array|string $fields)

Get a required_without rule builder instance.

requiredWithoutAll(array|string $fields)

Get a required_without_all rule builder instance.

static Timezone
timezone(array|null $arguments = null)

Get a timezone rule builder instance.

static Url
url()

Get a URL rule builder instance.

static Uuid
uuid()

Get a UUID rule builder instance.

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

Get a required_if rule builder instance.

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

Get a required_unless rule builder instance.

static ExcludeIf
excludeIf(Closure(): bool|bool $callback)

Get an exclude_if rule builder instance.

static ExcludeUnless
excludeUnless(Closure(): bool|bool $callback)

Get an exclude_unless rule builder instance.

static ProhibitedIf
prohibitedIf(Closure(): bool|bool $callback)

Get a prohibited_if rule builder instance.

prohibitedUnless(Closure(): bool|bool $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(class-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(bool $strict = false)

Get a numeric rule builder instance.

static AnyOf
anyOf(array $rules)

Get an "any of" rule builder instance.

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

Get a contains rule builder instance.

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

Get a "does not contain" rule builder instance.

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

Compile a set of rules for an attribute.

Details

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

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

Get a can constraint builder instance.

Parameters

string $ability
mixed ...$arguments

Return Value

Can

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

Apply the given rules if the given condition is truthy.

Parameters

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

Return Value

ConditionalRules

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

Apply the given rules if the given condition is falsy.

Parameters

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

Return Value

ConditionalRules

static ArrayRule array(array|null $keys = null)

Get an array rule builder instance.

Parameters

array|null $keys

Return Value

ArrayRule

static ArrayKeys arrayKeys(Arrayable|array|string $keys)

Get an array keys rule builder instance.

Parameters

Arrayable|array|string $keys

Return Value

ArrayKeys

static NestedRules forEach(callable $callback)

Create a new nested rule set.

Parameters

callable $callback

Return Value

NestedRules

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

Get a unique constraint builder instance.

Parameters

string $table
string $column

Return Value

Unique

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

Get an exists constraint builder instance.

Parameters

string $table
string $column

Return Value

Exists

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

Get an in rule builder instance.

Parameters

Arrayable|UnitEnum|array|string $values

Return Value

In

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

Get a not_in rule builder instance.

Parameters

Arrayable|UnitEnum|array|string $values

Return Value

NotIn

static string accepted()

Get an accepted validation rule.

Return Value

string

static string activeUrl()

Get an active_url validation rule.

Return Value

string

static string base64()

Get a base64 validation rule.

Return Value

string

static string bail()

Get a bail validation rule.

Return Value

string

static string boolean(bool $strict = false)

Get a boolean validation rule.

Parameters

bool $strict

Return Value

string

static string declined()

Get a declined validation rule.

Return Value

string

static string exclude()

Get an exclude validation rule.

Return Value

string

static string filled()

Get a filled validation rule.

Return Value

string

static string hexColor()

Get a hex_color validation rule.

Return Value

string

static string json()

Get a json validation rule.

Return Value

string

static ListRule list()

Get a list validation rule.

Return Value

ListRule

static string macAddress()

Get a mac_address validation rule.

Return Value

string

static string missing()

Get a missing validation rule.

Return Value

string

static string nullable()

Get a nullable validation rule.

Return Value

string

static string present()

Get a present validation rule.

Return Value

string

static string prohibited()

Get a prohibited validation rule.

Return Value

string

static string required()

Get a required validation rule.

Return Value

string

static string sometimes()

Get a sometimes validation rule.

Return Value

string

static string ulid()

Get an ulid validation rule.

Return Value

string

static AcceptedIf acceptedIf(string $anotherField, string|int|float|bool|null|array $value)

Get an accepted_if rule builder instance.

Parameters

string $anotherField
string|int|float|bool|null|array $value

Return Value

AcceptedIf

static DeclinedIf declinedIf(string $anotherField, string|int|float|bool|null|array $value)

Get a declined_if rule builder instance.

Parameters

string $anotherField
string|int|float|bool|null|array $value

Return Value

DeclinedIf

static MissingIf missingIf(string $anotherField, string|int|float|bool|null|array $value)

Get a missing_if rule builder instance.

Parameters

string $anotherField
string|int|float|bool|null|array $value

Return Value

MissingIf

static MissingUnless missingUnless(string $anotherField, string|int|float|bool|null|array $value)

Get a missing_unless rule builder instance.

Parameters

string $anotherField
string|int|float|bool|null|array $value

Return Value

MissingUnless

static PresentIf presentIf(string $anotherField, string|int|float|bool|null|array $value)

Get a present_if rule builder instance.

Parameters

string $anotherField
string|int|float|bool|null|array $value

Return Value

PresentIf

static PresentUnless presentUnless(string $anotherField, string|int|float|bool|null|array $value)

Get a present_unless rule builder instance.

Parameters

string $anotherField
string|int|float|bool|null|array $value

Return Value

PresentUnless

static Confirmed confirmed()

Get a confirmed rule builder instance.

Return Value

Confirmed

static CurrentPassword currentPassword()

Get a current_password rule builder instance.

Return Value

CurrentPassword

static Distinct distinct()

Get a distinct rule builder instance.

Return Value

Distinct

static ExcludeWith excludeWith(string $anotherField)

Get an exclude_with rule builder instance.

Parameters

string $anotherField

Return Value

ExcludeWith

static ExcludeWithout excludeWithout(array|string $anotherField)

Get an exclude_without rule builder instance.

Parameters

array|string $anotherField

Return Value

ExcludeWithout

static InArray inArray(string $otherField)

Get an in_array rule builder instance.

Parameters

string $otherField

Return Value

InArray

static InArrayKeys inArrayKeys(array|string $keys)

Get an in_array_keys rule builder instance.

Parameters

array|string $keys

Return Value

InArrayKeys

static IpAddress ip()

Get an IP address rule builder instance.

Return Value

IpAddress

static MissingWith missingWith(array|string $fields)

Get a missing_with rule builder instance.

Parameters

array|string $fields

Return Value

MissingWith

static MissingWithAll missingWithAll(array|string $fields)

Get a missing_with_all rule builder instance.

Parameters

array|string $fields

Return Value

MissingWithAll

static PresentWith presentWith(array|string $fields)

Get a present_with rule builder instance.

Parameters

array|string $fields

Return Value

PresentWith

static PresentWithAll presentWithAll(array|string $fields)

Get a present_with_all rule builder instance.

Parameters

array|string $fields

Return Value

PresentWithAll

static ProhibitedIfAccepted prohibitedIfAccepted(string $field)

Get a prohibited_if_accepted rule builder instance.

Parameters

string $field

Return Value

ProhibitedIfAccepted

static ProhibitedIfDeclined prohibitedIfDeclined(string $field)

Get a prohibited_if_declined rule builder instance.

Parameters

string $field

Return Value

ProhibitedIfDeclined

static Prohibits prohibits(array|string $fields)

Get a prohibits rule builder instance.

Parameters

array|string $fields

Return Value

Prohibits

static Regex regex(string $pattern)

Get a regex rule builder instance.

Parameters

string $pattern

Return Value

Regex

static NotRegex notRegex(string $pattern)

Get a not_regex rule builder instance.

Parameters

string $pattern

Return Value

NotRegex

static RequiredArrayKeys requiredArrayKeys(array|string $keys)

Get a required_array_keys rule builder instance.

Parameters

array|string $keys

Return Value

RequiredArrayKeys

static RequiredIfAccepted requiredIfAccepted(string $field)

Get a required_if_accepted rule builder instance.

Parameters

string $field

Return Value

RequiredIfAccepted

static RequiredIfDeclined requiredIfDeclined(string $field)

Get a required_if_declined rule builder instance.

Parameters

string $field

Return Value

RequiredIfDeclined

static RequiredWith requiredWith(array|string $fields)

Get a required_with rule builder instance.

Parameters

array|string $fields

Return Value

RequiredWith

static RequiredWithAll requiredWithAll(array|string $fields)

Get a required_with_all rule builder instance.

Parameters

array|string $fields

Return Value

RequiredWithAll

static RequiredWithout requiredWithout(array|string $fields)

Get a required_without rule builder instance.

Parameters

array|string $fields

Return Value

RequiredWithout

static RequiredWithoutAll requiredWithoutAll(array|string $fields)

Get a required_without_all rule builder instance.

Parameters

array|string $fields

Return Value

RequiredWithoutAll

static Timezone timezone(array|null $arguments = null)

Get a timezone rule builder instance.

Parameters

array|null $arguments

Return Value

Timezone

static Url url()

Get a URL rule builder instance.

Return Value

Url

static Uuid uuid()

Get a UUID rule builder instance.

Return Value

Uuid

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

Get a required_if rule builder instance.

Parameters

Closure(): bool|bool $callback

Return Value

RequiredIf

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

Get a required_unless rule builder instance.

Parameters

Closure(): bool|bool|null $callback

Return Value

RequiredUnless

static ExcludeIf excludeIf(Closure(): bool|bool $callback)

Get an exclude_if rule builder instance.

Parameters

Closure(): bool|bool $callback

Return Value

ExcludeIf

static ExcludeUnless excludeUnless(Closure(): bool|bool $callback)

Get an exclude_unless rule builder instance.

Parameters

Closure(): bool|bool $callback

Return Value

ExcludeUnless

static ProhibitedIf prohibitedIf(Closure(): bool|bool $callback)

Get a prohibited_if rule builder instance.

Parameters

Closure(): bool|bool $callback

Return Value

ProhibitedIf

static ProhibitedUnless prohibitedUnless(Closure(): bool|bool $callback)

Get a prohibited_unless rule builder instance.

Parameters

Closure(): bool|bool $callback

Return Value

ProhibitedUnless

static Date date()

Get a date rule builder instance.

Return Value

Date

static Date dateTime()

Get a datetime rule builder instance.

Return Value

Date

static Email email()

Get an email rule builder instance.

Return Value

Email

static Enum enum(class-string $type)

Get an enum rule builder instance.

Parameters

class-string $type

Return Value

Enum

static File file()

Get a file rule builder instance.

Return Value

File

static ImageFile imageFile(bool $allowSvg = false)

Get an image file rule builder instance.

Parameters

bool $allowSvg

Return Value

ImageFile

static Dimensions dimensions(array $constraints = [])

Get a dimensions rule builder instance.

Parameters

array $constraints

Return Value

Dimensions

static StringRule string()

Get a string rule builder instance.

Return Value

StringRule

static Numeric numeric(bool $strict = false)

Get a numeric rule builder instance.

Parameters

bool $strict

Return Value

Numeric

static AnyOf anyOf(array $rules)

Get an "any of" rule builder instance.

Parameters

array $rules

Return Value

AnyOf

Exceptions

InvalidArgumentException

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

Get a contains rule builder instance.

Parameters

Arrayable|UnitEnum|array|string $values

Return Value

Contains

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

Get a "does not contain" rule builder instance.

Parameters

Arrayable|UnitEnum|array|string $values

Return Value

DoesntContain

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

Compile a set of rules for an attribute.

Parameters

string $attribute
array $rules
array|null $data

Return Value

object|stdClass