Search code examples
phplaravellaravel-5laravel-artisan

Laravel command - ask always returning true?


I have this piece of code:

if($this->ask('Is this holiday booked? [y|N]')) {
     $holiday->booked = true;
} else {
     $holiday->booked = false;  
}

in a Laravel 5.2 command, but whatever the response it always seems to return true.

I also tried:

if($this->ask('Is this holiday booked? [y|N]') === true) {
    $holiday->booked = true;
} else {
    $holiday->booked = false;  
}

But this always enters it into the database as false regardless of if I enter y or n.

It will no doubt be something stupid, but can anyone see where I'm going wrong?


Solution

  • Ended up using:

    if(!$this->confirm('Is this holiday booked? [y|N]'), false) {
        $holiday->booked = false;
    } else {
        $holiday->booked = true;
    }