phplaravellaravel-artisan

How to abort or stop code in laravel-zero when i have multiple task?


I have multiple laravel-zero task like this, how to stop all task below if task A false condition?

$this->task("Task A", function () {
  if (!condition) {
   return false;
   exit;
   die;
  }
});

$this->task("Task B", function () {
  return true;
});

I want if condition in Task A false, abort all task below, i try exit, die, and $this->stop() but task in below keep running? any suggestion how i handle this?


Solution

  • Finally I use this approach:

    $taskA = $this->task("Task A", function () {
      if (!condition) {
       return false;
      }
    });
    
    if(!$taskA) {
      exit;
    }
    
    $this->task("Task B", function () {
      return true;
    });