PHP code example of ycs77 / laravel-form-field-type

1. Go to this page and download the library: Download ycs77/laravel-form-field-type 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/ */

    

ycs77 / laravel-form-field-type example snippets




namespace App\FormFields;

use Ycs77\LaravelFormFieldType\FormFields;

class UserFormFields extends FormFields
{
    /**
     * Return form fields array.
     *
     * @return array
     */
    public function fields()
    {
        return [
            'name' => [
                'rules' => '



namespace App\Http\Controllers;

use App\FormFields\UserFormFields;
use Illuminate\Http\Request;
use Ycs77\LaravelFormFieldType\Traits\FormFieldsTrait;

class MyController extends Controller 
{
    use FormFieldsTrait;

    protected $formFields;

    public function __construct(UserFormFields $formFields)
    {
        $this->formFields = $formFields;
    }

    public function index()
    {
        $form = $this->renderForm([
            'url'    => '/url',
            'method' => 'POST',
        ]);

        // Response view ...
    }

    public function store(Request $request)
    {
        $data = $this->validateFormData($request);

        // Save model data ...
    }
}


protected $validateMessage = [
    'dimensions' => 'The maximum length and width of the image is 4000x4000px.',
];

protected $failedMessage = [
    'images' => 'Can only upload up to 5 images.',
];

protected $langPath = 'validation.attributes';

$array = FieldType::type('age', [
    'type' => 'number',
]);

// [
//     'id'   => 'age',
//     'type' => 'number',
// ]

$array = FieldType::type('age', 'number');

// [
//     'id'   => 'age',
//     'type' => 'number',
// ]

$array = FieldType::type('nickname', [
    'type' => 'name',
    'rules' => 'les' => '

$array = FieldType::type('name', [
    'rules' => ' => 'text',
//     'rules' => '

$array = FieldType::type('name', [
    'type' => 'name',
    'front_rules' => '> '

$fields = [
    'name',
    'age' => [
        'type' => 'number',
    ],
];
$array = FieldType::fields($fields);

// [
//     [
//         'id'    => 'name',
//         'type'  => 'text',
//         'rules' => '

$fields = [
    'name',
    'age' => [
        'type' => 'number',
    ],
];
$array = FieldType::list($fields);

// ['name', 'age']

$fields = [
    'name',
    'meeting_time' => [
        'type'  => 'datetime-local',
        'rules' => 'ieldType::casts($fields, $data);

// [
//     'name'         => 'Bob',
//     'meeting_time' => '2018-01-01 00:00:00',
// ]

$form = $this->plain();
$fields = [
    'name',
    'meeting_time' => [
        'type' => 'datetime-local',
        'rules' => 'rm.

$fields = [
    'name',
    'phone' => [
        'rules' => '  ],
];
$array = FieldType::rules($fields);

// [
//     'name'  => '
bash
php artisan vendor:publish --tag=laravel-form-field-type-config

php artisan make:formfields UserFormFields