tinkerun: Dynamic Snippet Form problem

Hi, At first, thanks for your efforts doing this great app.

Today I have an idea about to make Snippet Form dynamic, so I did something like this:

use App\Models\User;

$users = User::selectRaw('first_name as label, id as value')->get()->toArray();

$field_user = [
    'value' => '',
    'label' => 'User',
    'description' => 'Select a user.',
    'type' => 'select',
    'options' => $users, 
];

But as soon as I click the Snippet Form button, I get this white empty screen: image

I was trying to populate the User select from the DB, also I was planning to use the $field_user value as an input for a second DB query, so the chosen value for $field_user will customize the result of the second query!

I know maybe the feature was not design to work as I wanted, but when I think about it, supporting dynamic Snippet Form will make the possibilities endless for Tinkerun

Also another request: I will be grateful if you implemented a self-update feature in Tinkerun, so we always have the latest and greatest without checking Tinkerun website every week or so

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 23 (11 by maintainers)

Commits related to this issue

Most upvoted comments

yes, I have not done the dynamic Snippet Form yet.

how about writing the dynamic data in the closure

for your case above:

$field_user = [
    'value' => '',
    'label' => 'User',
    'description' => 'Select a user.',
    'type' => 'select',
    'options' => function() {
		return User::selectRaw('first_name as label, id as value')->get()->toArray();
	}, 
];

with the closure, so I can just run code in the closure only with tinker for getting the dynamic data.

@diaafares yes, I think so. I will do it when I am free

Dynamic Snippet Form

😉 Already available in v0.2.5