I published a package for using Opis JSON Schema to FormRequest on laravel
https://github.com/mesak/laravel-opis-validator
installation
composer require mesak/laravel-opis-validator
Example
Requests
<?php
namespace App\Http\Requests;
use Mesak\LaravelOpisValidator\JsonSchemaRequest;
class JsonSchema extends JsonSchemaRequest
{
protected $extendValidatorMessage = true;
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'$schema' => "http://json-schema.org/draft-07/schema#",
"type" => "object",
"title" => "Base Preference",
"description" => "Base Preference Setting",
"properties" => [
"limit" => [
"type" => "integer",
"minimum" => 5,
"maximum" => 15,
"title" => "limit",
"attrs" => [
"placeholder" => "limit (limit)"
]
],
"page" => [
"type" => "object",
"title" => "Page",
"attrs" => [
"placeholder" => "Page ( Page )"
],
"properties" => [
"limit" => [
"type" => "integer"
]
]
]
],
"additionalProperties" => false,
"required" => [
"limit",
"page"
]
];
}
Controller
use App\Http\Requests\JsonSchema as JsonSchemaRequest;
public function update(JsonSchemaRequest $request)
{
dd($request->validated());
}
Top comments (0)