PHP code example of tihloh / prefab-input

1. Go to this page and download the library: Download tihloh/prefab-input 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/ */

    

tihloh / prefab-input example snippets


use Tihloh\Prefab\Input\Input;

$result = Input::from($_POST)->process([
    'name' => 'trim|'active' => 'default:true|boolean',
]);

if ($result->fails()) {
    print_r($result->errors());
    return;
}

$data = $result->validated();

[
    'name' => 'Christian',
    'email' => '[email protected]',
    'role' => 'admin',
    'is_superuser' => true,
]

$result = Input::from($data)->process([
    'name' => 'trim|

$result->validated();

[
    'name' => 'Christian',
    'email' => '[email protected]',
]

'name' => 'trim|

'name' => [
    'trim',
    '
]

$result = Input::from([
    'email' => '  [email protected] ',
    'age' => '35',
    'active' => 'true',
])->process([
    'email' => 'trim|lowercase|email',
    'age' => 'integer|min:18',
    'active' => 'boolean',
]);

[
    'email' => '[email protected]',
    'age' => 35,
    'active' => true,
]

'name' => 'me' => 'nullable|trim|string|max:100'
'bio' => 'sometimes|trim|string|max:500'
'active' => 'default:true|boolean'
'page' => 'default:1|integer|min:1'

'company_name' => '=> '

'items.*.type' => '

$result = Input::from([
    'user' => [
        'name' => ' Christian ',
        'email' => '[email protected]',
    ],
])->process([
    'user.name' => 'trim|

[
    'user' => [
        'name' => 'Christian',
        'email' => '[email protected]',
    ],
]

[
    'tags' => ['PHP', 'Go'],
]

$result = Input::from($_POST)->process([
    'tags' => '

[
    'items' => [
        ['product_id' => '10', 'qty' => '2'],
        ['product_id' => '15', 'qty' => '3'],
    ],
]

$result = Input::from($_POST)->process([
    'items' => 'ms.*.qty' => '

[
    'items' => [
        ['product_id' => 10, 'qty' => 2],
        ['product_id' => 15, 'qty' => 3],
    ],
]

[
    'items.1.qty' => [
        'The items 1 qty field must be at least 1.',
    ],
]

'departments.*.employees.*.email' => 'trim|lowercase|

[
    'items' => [
        [
            'product_id' => 10,
            'qty' => 2,
            'price' => 0,
            'is_free' => true,
        ],
    ],
]

[
    'items' => 'array',
    'items.*.product_id' => 'integer',
    'items.*.qty' => 'integer',
]

[
    'items' => [
        [
            'product_id' => 10,
            'qty' => 2,
        ],
    ],
]

$input = Input::fromRequest();

$input = Input::from($_POST, $_FILES);

$result = Input::fromRequest()->process([
    'title' => 'trim|

use Tihloh\Prefab\Input\UploadedFile;

$file = $result->validated('document');

if ($file instanceof UploadedFile) {
    $file->name();
    $file->tmpPath();
    $file->size();
    $file->extension();
    $file->mime();
    $file->error();
    $file->isValid();
    $file->isImage();
    $file->dimensions();
}

'photo' => '=> 'age|mimetypes:image/jpeg,image/png'

'photo' => 'image|dimensions:min_width=200,min_height=200,max_width=4000,max_height=4000'

[
    'attachments' => [
        UploadedFile,
        UploadedFile,
    ],
]

$result = Input::fromRequest()->process([
    'attachments' => 'array|max:10',
    'attachments.*' => 'file|max_size:10mb',
]);

$result = Input::fromRequest()->process([
    'employees' => ' 'employees.*.photo' => 'nullable|image|max_size:5mb',
]);

$result = Input::fromRequest()->process([
    'title' => 'trim|=> 'sometimes|array|max:10',
    'tags.*' => 'trim|string',
]);

$result->passes();
$result->fails();
$result->raw();
$result->all();
$result->validated();
$result->validated('document');
$result->errors();
$result->first();
$result->first('email');
$result->value('user.email');

$input->attributes([
    'email_address' => 'Email address',
    'items.*.qty' => 'Item quantity',
]);

$input->messages([
    'email.

$input->rule('even', function ($field, $value) {
    return is_int($value) && $value % 2 === 0
        ? null
        : 'The value must be an even integer.';
});

$result = $input->process([
    'quantity' => 'integer|even',
]);

$result = $input->process([
    'username' => [
        'trim',
        'ing) $value, ' ')
                ? 'Username cannot contain spaces.'
                : null;
        },
    ],
]);

$input->transform('phone', function ($value) {
    return preg_replace('/[^0-9+]/', '', (string) $value);
});

$result = $input->process([
    'phone' => 'trim|phone|

$input->rule('unique_email', function ($field, $value) use ($users) {
    return $users->findByEmail((string) $value) === null
        ? null
        : 'That email address is already in use.';
});

$result = $input->process([
    'email' => 'trim|lowercase|

$result = Input::from($_POST)->process([
    'name' => 'trim|

$result = Input::fromRequest()->process([
    'departments.*.employees.*.email' => 'trim|lowercase|