定制 wt-health/laravel-json-schema-request 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wt-health/laravel-json-schema-request

最新稳定版本:3.1.0

Composer 安装命令:

composer require wt-health/laravel-json-schema-request

包简介

Like FormRequests, but for validating against a json-schema

README 文档

README

CI Action Code Coverage Scrutinizer Code Quality

Laravels Form Request Validation for JSON Schema documents

Installation

 composer require wt-health/laravel-json-schema-request

Usage

The development experience is identical to Laravel's Form Request Validation, except instead of writing Laravel validation rules, you write a JSON Schema.

You can create a new request using the make:json-request command

artisan make:json-request MyJsonRequest

You will now have new request class App\Http\Requests\MyJsonRequest, Below you can see a basic example schema.

<?php

namespace App\Http\Requests;

use Wthealth\JsonSchemaRequest\JsonSchemaRequest;

class MyJsonRequest extends JsonSchemaRequest
{
    public function schema(): array
    {
        return [
            'type' => 'object',
            'properties' => [
                'first_name' => ['type' => 'string'],
                'last_name' => ['type' => 'string'],
                'email' => ['type' => 'string', 'format' => 'email'],
            ],
            'required' => ['first_name', 'last_name', 'email'],
            'additionalProperties' => false,
        ];
    }
}

Once you have a JsonSchemaRequest object, all you need to do is type-hint the request on your controller method. The incoming form request is validated before the controller method is called.

public function store(MyJsonRequest $request)
{
    // The incoming request is valid...

    // Retrieve the validated input data...
    $validated = $request->validated();
}

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 52.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-03