Skip to content

Latest commit

 

History

History
116 lines (84 loc) · 2.49 KB

FORM_MODE.md

File metadata and controls

116 lines (84 loc) · 2.49 KB

Form Mode

the Form Mode allow you run your Tinker code with form.

form-mode

How To Use

Write the Tinker code normally, and name the variable that needs to be converted into a form with a prefix.

for example:

$form_email = '[email protected]';
$form_password = 'secret';

$user = User::where('email', $form_email)->first();
$user->password = bcrypt($form_password);

$user->save();

$user;

the code will create two text fields in the form

image

Fields

text field

example:

$form_email = [
    'label' => 'Email',
    'description' => 'the email field description',
    'value' => '[email protected]',
    'type' => 'text',
]

image

  • value is required
  • type can be text email number etc, it’s same with <input/> type property

also you can just use

$form_email = '[email protected]';

is same as

$form_email = [
    'value' => '[email protected]',
];

select field

example:

$form_lang = [
    'label' => 'Language',
    'description' => 'the language you should choose',
    'value' => 'golang',
    'type' => 'select',
    'options' => [
        [
            'label' => 'PHP',
            'value' => 'php',
        ],
        [
            'label' => 'C++',
            'value' => 'cplusplus',
        ],
        [
            'label' => 'Go',
            'value' => 'golang',
        ]
    ]
];

image

  • value is required
  • type should be select
  • options is same with the <option/> tag in <select/>

checkbox field

example:

$form_is_admin = [
    'label' => 'Is Admin',
    'description' => 'the user is admin or not',
    'value' => false,
    'type' => 'checkbox',
]

image

  • value is required, and must be true or false
  • type should be checkbox

Prefix

the default prefix is form_, and you can also define yours in the VScode setinggs

image