I'm trying to create a optional console command.
$phone = $this->ask('Enter a phone number for the Seller (blank if not supplied)');
The problem is that if left blank I'll get:
[ERROR] A value is required.
Is there a work around for this to not require a response? Maybe something like ->nullable()
or similar?
By default answer to console question is required. Empty string is considered an empty answer, hence the error. You need to provide a default value and that should do the trick.
Try the following:
$phone = $this->ask('Enter a phone number for the Seller (blank if not supplied)', false);
If no phone number has been provided it will be given FALSE value. You can see if number was provided with
if ($phone !== FALSE) { //notice strict comparison !==
// number has been provided
} else {
// no number provided
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With