Example #1
0
 /**
  * Execute the console command.
  *
  * @param  \Illuminate\Contracts\Console\Kernel  $kernel
  *
  * @return void
  */
 public function handle(Kernel $kernel)
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $driver = $this->argument('driver');
     $action = $this->argument('action');
     $database = $this->option('database');
     if (!in_array($action, $this->actions)) {
         throw new InvalidArgumentException("Action [{$action}] is not available for this command.");
     }
     $command = "tenanti:{$action}";
     $parameters = ['driver' => $driver, '--database' => $database, '--force' => true];
     $migrator = $this->tenant->driver($driver);
     $migrator->executeByChunk(function ($entities) use($kernel, $command, $parameters) {
         foreach ($entities as $entity) {
             $parameters['--id'] = $entity->getKey();
             $kernel->queue($command, $parameters);
         }
     });
 }