Laravel Prompts Version
v0.1.12
Laravel Version
v10.29.0
PHP Version
8.2.11
Operating System & Version
Debian GNU/Linux 12 (bookworm) (php:8.2.11-fpm docker image)
Terminal Application
GNOME Terminal
Description
Hi Jess and Co. Prompts is a useful package and I appreciate the effort put in to it.
The relatively recent change f48bc94 forces SelectPrompt's $required bool|string
to not be false anymore.
This broke the prompts for me because of the way I use the SelectPrompt.
In my project, I give the user a number of options to choose from. The last option is sometimes called "Back" and sometimes called "Quit", and has a key of ''
(an empty string). For me an empty string is a consistent way of checking that the user wants to return from the current prompt / go back / exit / quit etc without having to worry about the wording. e.g.
$options = [
'database' => 'Database Management',
'deploy' => 'Deployment',
'' => 'Quit',
];
$choice = select(
label: "Main",
options: $options,
required: false, // <<<< This would allow '' (i.e. Quit) to be chosen
);
if ($choice === '') {
break;
}
(My actual code is abstracted and the $options are passed in, so it's less hard-coded than this).
I can get around it by setting $required to ''
, but it seems odd to solve it that way.
The commit explicitly checks to make sure that $required is not false, so I thought I'd ask about the reason behind that? Or am I simply not using it as intended?
Steps To Reproduce
$options = [
'database' => 'Database Management',
'deploy' => 'Deployment',
'' => 'Quit',
];
$choice = select(
label: "Main",
options: $options,
);
if ($choice === '') {
break;
}
The Quit option can't be picked.
β Main βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β Database Management β
β β Deployment β
β βΊ β Quit β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Required.