PHP code example of amirhs712 / rule-builder
1. Go to this page and download the library: Download amirhs712/rule-builder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amirhs712 / rule-builder example snippets
$rules = [
'username' => nope()->ringOf(30)->confirmed()->get() //[
$rules = [
'username' => nope()->stringOf(30)->toString(1), //string|max:30|lable
];
$rules = [
'date' => nope()->after('today')->get(),
'another_date' => nope()->afterOrEqual(now()->addMonth())->get(),
];
Rule::activeUrl($max)
->alpha($min, $max)
->alphaDash($min, $max)
->alphaNum($min, $max)
->array($min, $max)
->file($max)
->image($max)
->integer($min, $max)
->json($max)
->numeric($min, $max)
->string($min, $max)
->url($max);
$rules=[
'field1' => nope()->raw('string|max:30')->get(),
'field2' => nope()->raw(['string', 'max:30'])->get(),
'field3' => nope()->raw(new ValidationObject)->get(),
'field4' => nope()->raw([new ValidationObject, new AnotherObject])->get(),
'field5' => nope()->raw('string')->raw('max')->get(),
];
nope()->when($conditionIsMet, function(Nope $nope){
$nope->max(100);
});
$rules = [
'image1' => nope()->dimensions(['width' => 300, 'height' => 300])->get(),
'image2' => nope()->dimensions(Rule::dimensions()->width(300)->height(300))->get(),
];
nope()->myCustomExtendedRule($arg1, $arg2,...)->get(); //Results in: ["my_custom_extended_rule:$arg1, $arg2,..."]