How to create confirms Artisan Command Laravel recursively?

Asked

Viewed 14 times

1

Want to increment one more? (yes/no) [no]:

yes

counter = 1

Want to increment one more? (yes/no) [no]:

yes

counter = 2

Want to increment one more? (yes/no) [no]:

in the

Completed search.

  • This does not seem to be a recursive problem. Just a repeat loop already meets your need: while ($this->confirm('...')) { ... }

  • Yes @Woss agree, but you can put all your logic into while, the detail is that I saw someone with this doubt and one person said they had no way to ask sequential questions, but I didn’t find her post anymore!

1 answer

2

//Para fazer isso, podemos usar um laço while,  da seguinte maneira:


public function handle()
{

        $contador = 0;
        $confirmado = true;

        while ($confirmado) {
            if ($this->confirm('Deseja incrementar mais um?')) {
                $contador++;
                $this->info('contador = : '.$contador);
            } else {
                $confirmado = false;
            }
        }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.