initialized) { $previous_tenants_domain = tenant('domain'); } tenant()->all($this->option('tenants'))->each(function ($tenant) { $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); tenancy()->init($tenant['domain']); $callback = function ($prefix = '') { return function ($arguments, $argument) use ($prefix) { [$key, $value] = \explode('=', $argument, 2); $arguments[$prefix . $key] = $value; return $arguments; }; }; // Turns ['foo=bar', 'abc=xyz=zzz'] into ['foo' => 'bar', 'abc' => 'xyz=zzz'] $arguments = \array_reduce($this->option('argument'), $callback(), []); // Turns ['foo=bar', 'abc=xyz=zzz'] into ['--foo' => 'bar', '--abc' => 'xyz=zzz'] $options = \array_reduce($this->option('option'), $callback('--'), []); // Run command $this->call($this->argument('commandname'), \array_merge($arguments, $options)); tenancy()->end(); }); if ($tenancy_was_initialized) { tenancy()->init($previous_tenants_domain); } } }