amiralii / jsonschema-request
Laravel Server side form validation using JSON Schema
dev-master
2018-06-28 15:00 UTC
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-03-18 15:01:13 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"}
}
}';
}
}