punkrockio / laravel-schemarequest
Server side form validation using JSON Schema
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
pkg:composer/punkrockio/laravel-schemarequest
Requires
- php: >=5.5.9
- justinrainbow/json-schema: ^1.5
- laravel/framework: 5.1.*
Requires (Dev)
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2025-10-18 00:43:37 UTC
README
Server side form validation using JSON Schema
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"}
            }
        }';
    }
}