getCustomers()->each(function ($customer, $i) { if ($i > 0) { $this->getOutput()->writeln("\n"); } $this->getOutput()->writeln("{$customer}"); $this->call('migrate', ['--database' => $customer, '--force' => true]); $this->call('db:seed', ['--database' => $customer, '--force' => true]); }); return 0; } private function getCustomers() { return collect(json_decode(file_get_contents(base_path('connections.json')), true)) ->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus')) ->reject(fn ($config) => !$this->databaseExists($config['database'])) ->map(fn ($config, $customer) => $customer) ->sort() ->values(); } private function databaseExists($databaseName) { return !empty(DB::connection('schema')->select( "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$databaseName] )); } }