Lyger includes a powerful validation system with 20+ built-in rules, custom error messages, and form request classes for organizing validation logic.
Basic Validation
Use Validator::make() to create a validator:
useLyger\Validation\Validator;$validator=Validator::make($data,$rules);if($validator->fails()){returnResponse::json(['errors'=>$validator->errors()],422);}$validated=$validator->validated();// Only validated fields
Rules are combined as a pipe-delimited string or an array.
Presence
Rule
Description
required
Field must be present and not empty/null
Type Checking
Rule
Description
string
Must be a string
integer
Must be an integer
numeric
Must be numeric (int or float)
boolean
Must be a boolean (or 'true'/'false'/0/1)
array
Must be an array
Format
Rule
Description
email
Must be a valid email address
url
Must be a valid URL
ip
Must be a valid IP address
date
Must be parseable as a date (strtotime)
alpha
Must contain only letters
alpha_num
Must contain only letters and numbers
regex:/pattern/
Must match the given regular expression
Size & Length
Rule
Description
min:N
For strings: minimum length. For numbers: minimum value. For arrays: minimum count.
max:N
For strings: maximum length. For numbers: maximum value. For arrays: maximum count.
Inclusion
Rule
Description
in:val1,val2,...
Value must be one of the listed values
Confirmation
Rule
Description
confirmed
Field must match a {field}_confirmation field
Database
Rule
Description
unique
Value must not exist in the database (stub — extend to implement)
exists
Value must exist in the database (stub — extend to implement)
Custom Error Messages
Override the default error messages per field:
$validator=Validator::make($request->all(),['email'=>'required|email','age'=>'required|integer|min:18',],['email.required'=>'We need your email address.','email.email'=>'Please provide a valid email.','age.min'=>'You must be at least 18 years old.',]);
Checking Validation Results
$validator->validate();// Returns true/false$validator->fails();// true if there are errors$validator->errors();// ['field' => ['Error message', ...], ...]$validator->validated();// Only the validated fields (not extra input)
Form Requests
For complex validation, create a Form Request class to encapsulate rules and authorization:
# No rawr command yet — create manually in App/Requests/
<?phpnamespaceApp\Requests;useLyger\Validation\FormRequest;classStorePostRequestextendsFormRequest{publicfunctionauthorize():bool{// Return true to allow, false to deny (403)returntrue;}publicfunctionrules():array{return['title'=>'required|string|max:512','content'=>'required|string','published'=>'boolean',];}publicfunctionmessages():array{return['title.required'=>'A post title is required.','content.required'=>'Post content cannot be empty.',];}}