punkrockio/laravel-schemarequest
laravel-schemarequest
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"}
}
}';
}
}
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
631,580,251
9,707
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
404,034,618
608
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
387,976,821
4,658