1. Go to this page and download the library: Download square/laravel-hyrule 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/ */
// Initialize a new builder: it will help you build up your validation rule-set.
$builder = Hyrule::create();
// Describe your expected input:
// It needs the field name *and* the data-type.
// This creates a *Node* that you can then attach rules to:
$builder->string('first_name')
->
$builder
->string('first_name')
-> builder you are done w/ this field...
->string('last_name') // ...so you can start a new one!
->end();
$rules = $builder->build();
// $rules:
[
'' => ['
// Compile into an array Illuminate\Validation\Validator understands.
$rules = $builder->build();
// Use it e.g.
$validator = Validator::make($data, $rules);
// ...or
$request->validate($rules);
// etc.
$builder
// "nutritional_facts" is a ->teger('servings_per_container')
->quired()
->min(1)
->max(30)
->end()
// "fat", a nested field, has a bunch of nested fields, too.
->object('fat')
->integer('saturated_fat_grams')->end()
->integer('saturated_fat_percent')
->max(100)
->end();
->end();
Hyrule::create()
->string('name')
->end()
// etc.
Hyrule::create()
->allowUnknownProperties() // <- Allows unknown fields at root-level.
->object('data')
->allowUnknownProperties() // <- It does not carry-over. Add it to everywhere you wish to skip this.
// etc.
// Defines an array field named "tags"...
$builder
->array('tags')
// Array length must be between 1-10 elements long:
->min(1)
->max(10)
// ...and each element (i.e. a tag) must be a string between 3-100 chars in length.
->each('string')
->min('3')
->max('100');
// etc.
$builder
// Required "skus" must be between 1-10 items.
->array('skus')
->own:
->each('object')
// Each SKU has these fields:
->string('name')
->
$builder
->file('attachment')
-> ->end()
// etc.
// Adding built-in validation rules in Laravel
$builder
->string('foobar') // Returns a `StringNode` for the "foobar" field.
->le_type', 'car') // Adds "
$builder
->string('foobar')
// Converts camel-case to snake-case notation:
->barBaz('olives', 'on', 'pizza') // Adds "bar_baz:olives,on,pizza"
// Supports raw rule definitions:
->rule('
$builder = Hyrule::create() // The root
->string('name')
-> // New field on root:
->object('characteristics')
->ight_cm')
->end() // Back to "characteristics"
->with(...)
->end() // Back to $builder, the root node.
// Another field on root:
->array('siblings')
->max(10)
->each('object') // Starts the "*" ObjectNode
->string('name')
->end() // Back to the "*" ObjectNode
->end() // Back to "siblings"
->end() // Back to $builder, the root node.
// etc.