amiralii / jsonschema-request
Laravel Server side form validation using JSON Schema
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
pkg:composer/amiralii/jsonschema-request
Requires
- php: >=5.5.9
- dingo/api: 1.0.*@dev
- justinrainbow/json-schema: ^5.2
- laravel/framework: ^5.4
Requires (Dev)
- mockery/mockery: ^1.1
- phpunit/phpunit: ^7.1
This package is not auto-updated.
Last update: 2025-10-28 18:05:30 UTC
README
Laravel Server side form validation using JSON Schema
Install
composer require amiralii/jsonschema-request
How to use
- Create a form request class as you would with artisan: php artisan make:request PersonRequest
- Change the extended class in PersonRequest to use SchemaRequest/SchemaFormRequest
- Implement the rules() method to return a JSON Schema string
Example
<?php
namespace App\Http\Requests;
use SchemaRequest\SchemaFormRequest as Request;
class PersonFormRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return '{
            "type": "object",
            "properties": {
                "fname": {"type": "string", "maximum": 5},
                "lname": {"type": "string", "minimum": 5},
                "mname": {"type": "string", "minimum": 5},
                "age": {"type": "integer", "minimum": 21},
                "email": {"type": "string", "format": "email"}
            }
        }';
    }
}