the Form Mode allow you run your Tinker code with form.
Write the Tinker code normally, and name the variable that needs to be converted into a form with a prefix.
for example:
$form_email = 'pmoore@example.net';
$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
example:
$form_email = [
'label' => 'Email',
'description' => 'the email field description',
'value' => 'user@example.com',
'type' => 'text',
]
value
is requiredtype
can betext
email
number
etc, it’s same with<input/>
type property
also you can just use
$form_email = 'user@example.com';
is same as
$form_email = [
'value' => 'user@example.com',
];
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',
]
]
];
value
is requiredtype
should beselect
options
is same with the<option/>
tag in<select/>
example:
$form_is_admin = [
'label' => 'Is Admin',
'description' => 'the user is admin or not',
'value' => false,
'type' => 'checkbox',
]
value
is required, and must betrue
orfalse
type
should becheckbox
the default prefix is form_
, and you can also define yours in the VScode setinggs