REST Payload Validation for PHP Applications
codepoetry/request-validation
is a PHP library that provides functionality for validating REST API payloads in PHP applications. It helps you ensure that incoming data adheres to your specified rules and constraints, making your applications more robust and secure.
You can install this package via Composer:
composer require codepoetry/request-validation
- PHP >= 8.2
Here's a basic example of how to use this package:
Create ExampleRequest.php
file in app/Http/Requests
<?php
namespace App\Http\Requests;
use Codepoetry\RequestValidation\RequestAbstract;
class ExampleRequest extends RequestAbstract
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
"email" => "require"
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages(): array
{
return [
"email.unique" => trans('validation.email_unique'),
];
}
}
For detailed documentation and examples, please refer to the official documentation.
This package is proprietary software. See the LICENSE file for licensing information.
- Manab Roy - codepoetryindia@gmail.com - Manab's Website
Contributions are welcome! Please see our Contribution Guidelines for more details.
If you discover any issues or have questions, please feel free to open an issue in the issue tracker.
See the CHANGELOG.md file for information on recent changes.
- Special thanks to contributors who have helped improve this project.