`text` trackTypedValue when key is up and down.
utsavsomaiya opened this issue ยท 4 comments
Hey @jessarcher,
I don't know but sometimes I like this functionality.. Can we cached the last enter value?
prompts-2023-08-23_15.44.44.mp4
And yes as per my suggestions if you give the prompts validation to user then this error will give in validation actually.
laravel-2023-08-23_16.10.37.mp4
Hey @utsavsomaiya,
I don't know but sometimes I like this functionality.. Can we cached the last enter value?
I'm familiar with that functionality in shells and REPLs, but I'm struggling to think of a scenario with prompts where I would use it. Can you provide a real-world scenario where it would be useful?
Also, would you expect the values to be cached just for the lifetime of the command or to persist between different commands?
And would you expect the cached values to be shared across all prompts, or scoped to specific prompt instances (maybe using a hash of the label), prompt type, project, etc.?
And yes as per my suggestions if you give the prompts validation to user then this error will give in validation actually.
I can't speak for Taylor, but I'd be open to a PR that adds validation to the make:*
command text prompts by using a closure instead of the tuple syntax.
This could be applied globally in GeneratorCommand
something like this (untested):
/**
* Prompt for missing input arguments using the returned questions.
*
* @return array
*/
protected function promptForMissingArgumentsUsing()
{
return [
'name' => fn () => text(
label: 'What should the '.strtolower($this->type).' be named?',
placeholder: match ($this->type) {
'Cast' => 'E.g. Json',
'Channel' => 'E.g. OrderChannel',
'Console command' => 'E.g. SendEmails',
'Component' => 'E.g. Alert',
'Controller' => 'E.g. UserController',
'Event' => 'E.g. PodcastProcessed',
'Exception' => 'E.g. InvalidOrderException',
'Factory' => 'E.g. PostFactory',
'Job' => 'E.g. ProcessPodcast',
'Listener' => 'E.g. SendPodcastNotification',
'Mailable' => 'E.g. OrderShipped',
'Middleware' => 'E.g. EnsureTokenIsValid',
'Model' => 'E.g. Flight',
'Notification' => 'E.g. InvoicePaid',
'Observer' => 'E.g. UserObserver',
'Policy' => 'E.g. PostPolicy',
'Provider' => 'E.g. ElasticServiceProvider',
'Request' => 'E.g. StorePodcastRequest',
'Resource' => 'E.g. UserResource',
'Rule' => 'E.g. Uppercase',
'Scope' => 'E.g. TrendingScope',
'Seeder' => 'E.g. UserSeeder',
'Test' => 'E.g. UserTest',
default => '',
},
required: true,
validate: fn ($value) => match (true) {
$this->isReservedName($value) => 'The name "'.$value.'" is reserved by PHP.',
$this->alreadyExists($value) => $this->type.' already exists.',
default => null
},
),
];
}
I already done this yesterday. Have you seen this? http://github.com/laravel/framework/pull/48147. He said no plans to merge.๐
I don't know. May be I am wrong.
I will share the real use case after couple of hours.
I already done this yesterday. Have you seen this? http://github.com/laravel/framework/pull/48147. He said no plans to merge.๐
I didn't see that one, sorry. My only issues with that PR are that the validation was removed if the name was passed as a command-line argument, the return type was incorrectly changed, and I don't think $this->getNameInput()
would have returned the entered value because at that point the command wouldn't be aware of it. It would also have been good to include the "already exists" check from my example above. Maybe if we start getting reports from people legitimately expecting those errors, we can revisit it.
As for this feature request, I don't think it's something we want to add right now, but if you come up with a useful real-world scenario for it, then we can reconsider ๐