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|array|string $rules, ValidationRule|InvokableRule|Rule|Closure|array|string $defaultRules = [])

Apply the given rules if the given condition is truthy.

unless(callable|bool $condition, ValidationRule|InvokableRule|Rule|Closure|array|string $rules, ValidationRule|InvokableRule|Rule|Closure|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 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|BackedEnum|UnitEnum|array|string $values)

Get an in rule builder instance.

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

Get a not_in rule builder instance.

static RequiredIf
requiredIf(callable|bool $callback)

Get a required_if rule builder instance.

static ExcludeIf
excludeIf(callable|bool $callback)

Get a exclude_if rule builder instance.

static ProhibitedIf
prohibitedIf(callable|bool $callback)

Get a prohibited_if 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()

Get an image file rule builder instance.

static Dimensions
dimensions(array $constraints = [])

Get a dimensions rule builder instance.

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|array|string $rules, ValidationRule|InvokableRule|Rule|Closure|array|string $defaultRules = [])

Apply the given rules if the given condition is truthy.

Parameters

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

Return Value

ConditionalRules

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

Apply the given rules if the given condition is falsy.

Parameters

callable|bool $condition
ValidationRule|InvokableRule|Rule|Closure|array|string $rules
ValidationRule|InvokableRule|Rule|Closure|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 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|BackedEnum|UnitEnum|array|string $values)

Get an in rule builder instance.

Parameters

Arrayable|BackedEnum|UnitEnum|array|string $values

Return Value

In

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

Get a not_in rule builder instance.

Parameters

Arrayable|BackedEnum|UnitEnum|array|string $values

Return Value

NotIn

static RequiredIf requiredIf(callable|bool $callback)

Get a required_if rule builder instance.

Parameters

callable|bool $callback

Return Value

RequiredIf

static ExcludeIf excludeIf(callable|bool $callback)

Get a exclude_if rule builder instance.

Parameters

callable|bool $callback

Return Value

ExcludeIf

static ProhibitedIf prohibitedIf(callable|bool $callback)

Get a prohibited_if rule builder instance.

Parameters

callable|bool $callback

Return Value

ProhibitedIf

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()

Get an image file rule builder instance.

Return Value

ImageFile

static Dimensions dimensions(array $constraints = [])

Get a dimensions rule builder instance.

Parameters

array $constraints

Return Value

Dimensions