getTenant(); tenancy()->all($this->option('tenants'))->each(function ($tenant) { $this->line("Tenant: {$tenant['id']}"); tenancy()->initialize($tenant); $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()->endTenancy(); }); if ($originalTenant) { tenancy()->initialize($originalTenant); } } }