PHP code example of riley19280 / laravel-rules-to-schema

1. Go to this page and download the library: Download riley19280/laravel-rules-to-schema library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

riley19280 / laravel-rules-to-schema example snippets


use \Illuminate\Foundation\Http\FormRequest;

$schema = LaravelRulesToSchema::parse(FormRequest|array $rules): FluentSchema

$schema->compile(); // Returns an array representation of the json schema 

// config/rules-to-schema.php

'custom_rule_schemas' => [
    // \CustomPackage\CustomRule::class => \Support\CustomRuleSchemaDefinition::class,
    // \CustomPackage\CustomRule::class => 'string',
    // \CustomPackage\CustomRule::class => ['null', 'string'],
],

// config/rules-to-schema.php

'parsers' => [
    ...
    \CustomPackage\CustomParser::class,
],

LaravelRulesToSchema::registerCustomRuleSchema(CustomRule::class, CustomRuleSchemaDefinition::class);
LaravelRulesToSchema::registerParser(CustomParser::class);