use ValidatorResolver\ValidatorResolver; $resolver = new ValidatorResolver(); $result = $resolver->resolve([ 'name' => 'John Doe', 'email' => 'johndoe@example.com', 'age' => '35', ], [ 'name' => 'required|string|min:3|max:255', 'email' => 'required|email|max:255', 'age' => 'required|integer|min:18|max:120', ]); if (!$result->isValid()) { // Handle validation errors $errors = $result->getErrors(); // ... } else { // Data is valid, do something with it $data = $result->getData(); // ... }
use ValidatorResolver\ValidatorResolver; $resolver = new ValidatorResolver(); $result = $resolver->resolveJson('{"name":"John Doe","email":"johndoe@example.com","age":35}', [ 'name' => 'required|string|min:3|max:255', 'email' => 'required|email|max:255', 'age' => 'required|integer|min:18|max:120', ]); if (!$result->isValid()) { // Handle validation errors $errors = $result->getErrors(); // ... } else { // Data is valid, do something with it $data = $result->getData(); // ... }This example shows how to use PHP Validator Resolver to validate JSON input data. The `resolveJson()` method takes the JSON input data as the first argument, and the validation rules as the second argument. PHP Validator Resolver is a third-party package library that can be installed via Composer. The package is available on Packagist under the name `validator-resolver/validator-resolver`.