Let's say I'm coding a command. How would I stop it completely in the middle of it running?
Example:
public function handle()
{
    if (!$this->good_times) {
        $this->error('Bad times');
        $this->exit();
    }
    // continue command stuff
}
I have tried:
throw new RuntimeException('Bad times');
But that dumps a bunch of ugliness in the terminal.
You can use return or exit if you want to stop the command from within a function.
Simply use Ctrl + C . It will come out to prompt state.
The Closure Commands (aka Closure Based Routes) are defined using the Artisan::command() in routes/console. php. • The command() accepts two arguments: The command signature and a Closure which receives the command's arguments and options.
To create a new artisan command, we can use the make:command artisan command. This command will make a new command class within the app/Console/Commands catalog. In case the directory does not exist in our laravel project, it'll be automatically made the primary time we run the artisan make:command command.
Just use a return statement instead of throwing an exception. Like...
public function handle()
{
    if (!$this->good_times) {
        $this->error('Bad times');
        // $this->exit();
        // throw new RuntimeException('Bad times');
        return;
    }
    // ...
}
                        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