1. Go to this page and download the library: Download infocyph/reqshield 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/ */
$validator = Validator::make($rules)
->strict(); // same as allowUnknown(false)
$validator = Validator::make($rules)
->stripUnknown(); // remove unknown fields instead of failing
'status' => '
'status' => [
'rules' => 'erStatus::class,
]
use Infocyph\ReqShield\Support\ValidationContext;
$validator->after(function (ValidationContext $ctx): void {
if ((string) $ctx->get('start_date') > (string) $ctx->get('end_date')) {
$ctx->addError('end_date', 'End date must be after start date.');
}
});
use Infocyph\ReqShield\Rules\Callback;
$validator = Validator::make([
'code' => [
' message: 'The code must be an even number'
),
],
]);
use Infocyph\ReqShield\Contracts\Rule;
class StrongPassword implements Rule
{
public function passes(mixed $value, string $field, array $data): bool
{
return strlen($value) >= 12
&& preg_match('/[A-Z]/', $value)
&& preg_match('/[a-z]/', $value)
&& preg_match('/[0-9]/', $value)
&& preg_match('/[^A-Za-z0-9]/', $value);
}
public function message(string $field): string
{
return "The {$field} must be at least 12 characters with uppercase, lowercase, number, and special character.";
}
public function cost(): int { return 20; }
public function isBatchable(): bool { return false; }
}
// Usage
$validator = Validator::make([
'password' => ['
use Infocyph\ReqShield\Validator;
use Infocyph\ReqShield\Contracts\DatabaseProvider;
// Implement your database provider
class MyDatabaseProvider implements DatabaseProvider
{
// Implement