Menu

## Validator
in package
Uses ValidationTrait

Validator.php : 10

This class is used to validate data

### Table of Contents

#### Properties

$hayStack : Arrayable|null
$hook : string
  The hook to validate
$ip_pattern : string
$password_pattern : string
$phone_pattern : string
$slug_pattern : string
$throwsExceptions : bool

#### Methods

are() : Validator
array() : static
  Ensures that the field is an array
asDomain() : Validator
asEmail() : Validator
  Validates emails of all formats
asInternationalPhone() : bool|int
  Will only validate international numbers if the code is provided, otherwise, will validate local only
asIp() : Validator
asMac() : Validator
asNumber() : static
asNumeric() : static
asNumericInt() : static
asPassword() : static
  Validates the rules as follows - At least one integer - At least one lowercase alpha letter - At least one Uppercase alpha letter - At least one special character
asSlug() : Validator
asUrl() : Validator
bool() : static
  Ensures that the field is a boolean
date() : static
  Ensures that the field is a date
doesNotMatch() : static
  Check if the value of the field is not equal to the value of another field
email() : static
  Ensures that the field is an email
float() : static
  Ensures that the field is a float
get() : Validator
  Get the value of hook
int() : static
  Ensures that the field is an integer
matches() : static
  Check if the value of the field is equal to the value of another field
required() : static
  Marks the field as required
requiredIf() : Validator
  Required if the condition is met by the hook
requiredUnless() : static
  Required unless the condition is met by the field
requiredWith() : static
  Only required if the field is present/defined
requiredWithout() : static
  Only required if the field is not present/defined
string() : static
  Ensures that the field is a string
validate() : static
valueOf() : Validator
  Get the value of hook
_validate() : bool|int
  Use this to cover scenarios this contract does not cover
_validateFilter() : int|bool
  Internal validator based on PHP filter_var validations
getOrFail() : mixed
is() : Validator
  Check if the value matches the expected value

### Properties

#### $hayStack

Validator.php : 20
`protected Arrayable|null $hayStack`

The data to validate against

#### $hook

Validator.php : 16

The hook to validate

`protected string $hook`

#### $ip_pattern

ValidationTrait.php : 14
`private string $ip_pattern = "/^(\\d{1,3}\\.){3}\\d{1,3}\$/"`

#### $password_pattern

ValidationTrait.php : 13
`private string $password_pattern = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*(_|[^\\w])).+\$/"`

#### $phone_pattern

ValidationTrait.php : 12
`private string $phone_pattern = "/^[+]{1}(?:[0-9\\-\\(\\)\\/.]\\s?){6,15}[0-9]{1}\$/"`

#### $slug_pattern

ValidationTrait.php : 15
`private string $slug_pattern = "/^[a-z0-9-]+\$/"`

#### $throwsExceptions

ValidationTrait.php : 16
`private bool $throwsExceptions = true`

### Methods

#### are()

ValidationTrait.php : 254
`public are(string $expected[, string|null $message = 'Invalid data' ]) : Validator`

##### Parameters

$expected : string
$message : string|null = 'Invalid data'

##### Tags

throws
  Exception

##### Return values

Validator

#### array()

ValidationTrait.php : 346

Ensures that the field is an array

`public array([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### asDomain()

ValidationTrait.php : 190
`public asDomain([string|null $regex = null ]) : Validator`

##### Parameters

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  Exception

##### Return values

Validator

#### asEmail()

ValidationTrait.php : 50

Validates emails of all formats

`public asEmail([string|null $regex = null ][, string|null $message = 'Invalid email address' ]) : Validator`

##### Parameters

$regex : string|null = null
$message : string|null = 'Invalid email address'

##### Tags

throws
  Exception

##### Return values

Validator

#### asInternationalPhone()

ValidationTrait.php : 71

Will only validate international numbers if the code is provided, otherwise, will validate local only

`public asInternationalPhone([string|null $code = null ][, string|null $regex = null ][, string|null $message = 'Invalid phone number' ]) : bool|int`

##### Parameters

$code : string|null = null

  International country that you want to check against

$regex : string|null = null

  Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid phone number'

##### Tags

throws
  Exception

##### Return values

bool|int

#### asIp()

ValidationTrait.php : 159
`public asIp([string|null $regex = null ][, string|null $message = 'Invalid IP address' ]) : Validator`

##### Parameters

$regex : string|null = null

  Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid IP address'

##### Tags

throws
  Exception

##### Return values

Validator

#### asMac()

ValidationTrait.php : 174
`public asMac([string|null $regex = null ]) : Validator`

##### Parameters

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  Exception

##### Return values

Validator

#### asNumber()

ValidationTrait.php : 105
`public asNumber([string|null $message = 'Invalid Number' ]) : static`

##### Parameters

$message : string|null = 'Invalid Number'

##### Tags

throws
  Exception

##### Return values

static

#### asNumeric()

ValidationTrait.php : 115
`public asNumeric([string|null $message = 'Invalid Numeric' ]) : static`

##### Parameters

$message : string|null = 'Invalid Numeric'

##### Tags

throws
  Exception

##### Return values

static

#### asNumericInt()

ValidationTrait.php : 125
`public asNumericInt([string|null $message = 'Invalid Numeric Integer' ]) : static`

##### Parameters

$message : string|null = 'Invalid Numeric Integer'

##### Tags

throws
  Exception

##### Return values

static

#### asPassword()

ValidationTrait.php : 96

Validates the rules as follows - At least one integer - At least one lowercase alpha letter - At least one Uppercase alpha letter - At least one special character

`public asPassword([string|null $regex = null ][, string|null $message = 'Week Password' ]) : static`

##### Parameters

$regex : string|null = null

  Your custom regular expression we can depend on instead.

$message : string|null = 'Week Password'

##### Tags

throws
  Exception

##### Return values

static

#### asSlug()

ValidationTrait.php : 212
`public asSlug([string|null $regex = null ]) : Validator`

##### Parameters

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  Exception
example

      $slug = 'fsjkfjshfsjk-skdhfkjdfsj-skdjfhjskdf'; // valid slug
      $slug2 = 'sfksdfsdskljfhsdhjkfhsdsfsdfsfsd'; // valid slug
      $slug3 = 'dkfl ksjfhsdk/skjdfsk%'; // invalid slug

##### Return values

Validator

#### asUrl()

ValidationTrait.php : 140
`public asUrl([string|null $regex = null ][, string|null $message = 'Invalid URL' ]) : Validator`

##### Parameters

$regex : string|null = null

  Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid URL'

##### Tags

throws
  Exception

##### Return values

Validator

#### bool()

ValidationTrait.php : 318

Ensures that the field is a boolean

`public bool([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### date()

ValidationTrait.php : 360

Ensures that the field is a date

`public date([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### doesNotMatch()

ValidationTrait.php : 459

Check if the value of the field is not equal to the value of another field

`public doesNotMatch(string $field[, string|null $message = null ]) : static`

##### Parameters

$field : string
$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### email()

ValidationTrait.php : 374

Ensures that the field is an email

`public email([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### float()

ValidationTrait.php : 332

Ensures that the field is a float

`public float([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### get()

Validator.php : 26

Get the value of hook

`public get() : Validator`

##### Return values

Validator

#### int()

ValidationTrait.php : 290

Ensures that the field is an integer

`public int([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### matches()

ValidationTrait.php : 438

Check if the value of the field is equal to the value of another field

`public matches(string $field[, string|null $message = null ]) : static`

##### Parameters

$field : string
$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### required()

ValidationTrait.php : 276

Marks the field as required

`public required([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### requiredIf()

ValidationTrait.php : 390

Required if the condition is met by the hook

`public requiredIf(string $field, callable $condition) : Validator`

##### Parameters

$field : string
$condition : callable

  The condition to check against. Receives the instance of the validator

##### Tags

throws
  Exception

##### Return values

Validator

#### requiredUnless()

ValidationTrait.php : 402

Required unless the condition is met by the field

`public requiredUnless(string $field, callable $condition) : static`

##### Parameters

$field : string
$condition : callable

##### Tags

throws
  Exception

##### Return values

static

#### requiredWith()

ValidationTrait.php : 414

Only required if the field is present/defined

`public requiredWith(string $field) : static`

##### Parameters

$field : string

##### Tags

throws
  Exception

##### Return values

static

#### requiredWithout()

ValidationTrait.php : 426

Only required if the field is not present/defined

`public requiredWithout(string $field) : static`

##### Parameters

$field : string

##### Tags

throws
  Exception

##### Return values

static

#### string()

ValidationTrait.php : 304

Ensures that the field is a string

`public string([string|null $message = null ]) : static`

##### Parameters

$message : string|null = null

##### Tags

throws
  Exception

##### Return values

static

#### validate()

ValidationTrait.php : 264
`public static validate(string $keyToValidate, Arrayable|null $data) : static`

##### Parameters

$keyToValidate : string
$data : Arrayable|null

##### Return values

static

#### valueOf()

Validator.php : 36

Get the value of hook

`public valueOf(string $hook) : Validator`

##### Parameters

$hook : string

##### Return values

Validator

#### _validate()

ValidationTrait.php : 25

Use this to cover scenarios this contract does not cover

`private _validate(string $regex[, string|null $message = 'Invalid data' ]) : bool|int`

##### Parameters

$regex : string
  - The regular expression to check against
$message : string|null = 'Invalid data'
  - The message to throw if the value is invalid and we are in the exceptions mode

##### Tags

throws
  Exception

##### Return values

bool|int

#### _validateFilter()

ValidationTrait.php : 227

Internal validator based on PHP filter_var validations

`private _validateFilter( $filterType[, string $message = 'Invalid Data' ]) : int|bool`

##### Parameters

$filterType :
$message : string = 'Invalid Data'

##### Tags

throws
  Exception

##### Return values

int|bool

#### getOrFail()

ValidationTrait.php : 38
`private getOrFail() : mixed`

##### Tags

throws
  Exception

#### is()

ValidationTrait.php : 244

Check if the value matches the expected value

`private is(string $expected[, string|null $message = 'Invalid data' ]) : Validator`

##### Parameters

$expected : string
$message : string|null = 'Invalid data'

##### Tags

throws
  Exception

##### Return values

Validator

## Search results