Laravel FormRequest с валидатором Opis

Я опубликовал пакет для использования Opis JSON Schema в FormRequest на laravel

https://github.com/mesak/laravel-opis-validator

установка

composer require mesak/laravel-opis-validator
Вход в полноэкранный режим Выйти из полноэкранного режима

Пример

Запросы

<?php

namespace AppHttpRequests;

use MesakLaravelOpisValidatorJsonSchemaRequest;

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"
            ]
        ];
    }
Войти в полноэкранный режим Выйти из полноэкранного режима

Контроллер


use AppHttpRequestsJsonSchema as JsonSchemaRequest;

    public function update(JsonSchemaRequest $request)
    {
        dd($request->validated());
    }
Войти в полноэкранный режим Выход из полноэкранного режима

Оцените статью
devanswers.ru
Добавить комментарий