1

How to ask for input and loop it until user inputs in command line using lumen ?

by the default I can create a custom command in the app/Console/Commands directory

here's my current code

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use \Exception;


class AskmeCommand extends Command
{


    protected  $signature = "askme";

    protected $description = "Ask Me";

    public function __construct() {
        parent::__construct();
    }

    public function handle()
    {
        $this->question("ask me question?");
        try {
            $this->info("Hello World");
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }
}

if I run this code via php artisan askme all it does is print the "ask me question" how should the user type the input/question in the command line? then how to loop the question again ?

sasori
  • 5,249
  • 16
  • 86
  • 138

1 Answers1

1

I think it should give you an error as I don't see Command::question() at all but there is ask()

https://laravel.com/docs/8.x/artisan#prompting-for-input

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $name = $this->ask('What is your name?');
}

https://laravel.com/api/5.8/Illuminate/Console/Command.html#method_ask

mixed ask(string $question, string|null $default = null)
Daniel W.
  • 31,164
  • 13
  • 93
  • 151