codepoetry/request-validation

REST Payload validation for PHP applications.

1.0.5 2023-09-09 11:29 UTC

This package is auto-updated.

Last update: 2024-05-09 14:23:26 UTC


README

REST Payload Validation for PHP Applications

License

Description

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.

Installation

You can install this package via Composer:

composer require codepoetry/request-validation

Requirements

  • PHP >= 8.2

Usage

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'),
        ];
    }
}

Documentation

For detailed documentation and examples, please refer to the official documentation.

License

This package is proprietary software. See the LICENSE file for licensing information.

Author

Contributing

Contributions are welcome! Please see our Contribution Guidelines for more details.

Issues

If you discover any issues or have questions, please feel free to open an issue in the issue tracker.

Changelog

See the CHANGELOG.md file for information on recent changes.

Acknowledgments

  • Special thanks to contributors who have helped improve this project.