ValidationTrait
Table of Contents
Properties
- $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
- 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
- _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
$ip_pattern
private
string
$ip_pattern
= "/^(\\d{1,3}\\.){3}\\d{1,3}\$/"
$password_pattern
private
string
$password_pattern
= "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*(_|[^\\w])).+\$/"
$phone_pattern
private
string
$phone_pattern
= "/^[+]{1}(?:[0-9\\-\\(\\)\\/.]\\s?){6,15}[0-9]{1}\$/"
$slug_pattern
private
string
$slug_pattern
= "/^[a-z0-9-]+\$/"
$throwsExceptions
private
bool
$throwsExceptions
= true
Methods
are()
public
are(string $expected[, string|null $message = 'Invalid data' ]) : Validator
Parameters
- $expected : string
- $message : string|null = 'Invalid data'
Tags
Return values
Validatorarray()
Ensures that the field is an array
public
array([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticasDomain()
public
asDomain([string|null $regex = null ]) : Validator
Parameters
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
ValidatorasEmail()
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
Return values
ValidatorasInternationalPhone()
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
Return values
bool|intasIp()
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
Return values
ValidatorasMac()
public
asMac([string|null $regex = null ]) : Validator
Parameters
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
ValidatorasNumber()
public
asNumber([string|null $message = 'Invalid Number' ]) : static
Parameters
- $message : string|null = 'Invalid Number'
Tags
Return values
staticasNumeric()
public
asNumeric([string|null $message = 'Invalid Numeric' ]) : static
Parameters
- $message : string|null = 'Invalid Numeric'
Tags
Return values
staticasNumericInt()
public
asNumericInt([string|null $message = 'Invalid Numeric Integer' ]) : static
Parameters
- $message : string|null = 'Invalid Numeric Integer'
Tags
Return values
staticasPassword()
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
Return values
staticasSlug()
public
asSlug([string|null $regex = null ]) : Validator
Parameters
- $regex : string|null = null
-
Your custom regular expression we can depend on instead.
Tags
Return values
ValidatorasUrl()
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
Return values
Validatorbool()
Ensures that the field is a boolean
public
bool([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticdate()
Ensures that the field is a date
public
date([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticdoesNotMatch()
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
Return values
staticemail()
Ensures that the field is an email
public
email([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticfloat()
Ensures that the field is a float
public
float([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticint()
Ensures that the field is an integer
public
int([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticmatches()
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
Return values
staticrequired()
Marks the field as required
public
required([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticrequiredIf()
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
Return values
ValidatorrequiredUnless()
Required unless the condition is met by the field
public
requiredUnless(string $field, callable $condition) : static
Parameters
- $field : string
- $condition : callable
Tags
Return values
staticrequiredWith()
Only required if the field is present/defined
public
requiredWith(string $field) : static
Parameters
- $field : string
Tags
Return values
staticrequiredWithout()
Only required if the field is not present/defined
public
requiredWithout(string $field) : static
Parameters
- $field : string
Tags
Return values
staticstring()
Ensures that the field is a string
public
string([string|null $message = null ]) : static
Parameters
- $message : string|null = null
Tags
Return values
staticvalidate()
public
static validate(string $keyToValidate, Arrayable|null $data) : static
Parameters
- $keyToValidate : string
- $data : Arrayable|null
Return values
static_validate()
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
Return values
bool|int_validateFilter()
Internal validator based on PHP filter_var validations
private
_validateFilter( $filterType[, string $message = 'Invalid Data' ]) : int|bool
Parameters
Tags
Return values
int|boolgetOrFail()
private
getOrFail() : mixed
Tags
is()
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'