Skip to content

Commit 7eaf4c4

Browse files
committed
States into Countries also for all Conutries
1 parent 34c3c22 commit 7eaf4c4

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/LaravelWcLocations.php

+15-10
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public function getCountries(
111111
if ($code && is_string($code)) {
112112
$code = [$code];
113113
}
114+
$countries = [];
114115
if ($code && is_array($code)) {
115-
$countries = [];
116116
foreach ($code as $country_code) {
117117
if (array_key_exists($country_code, $this->countries)) {
118118
$copy = new \ArrayObject($this->countries[$country_code]);
@@ -121,20 +121,25 @@ public function getCountries(
121121
if ($translate && $this->locale) {
122122
$country['name'] = $this->getTranslation($country['name'], 'country');
123123
}
124-
if ($with_states) {
125-
$country['states'] = $this->getStates(
126-
country_code: $country_code,
127-
translate: $translate
128-
);
129-
}
130-
$countries[$country_code] = (object) $country;
124+
$countries[$country_code] = $country;
131125
}
132126
}
127+
} else {
128+
$copy = new \ArrayObject($this->countries);
129+
$countries = $copy->getArrayCopy();
130+
unset($copy);
131+
}
133132

134-
return collect($countries);
133+
if ($with_states) {
134+
foreach ($countries as $country_code => $country) {
135+
$countries[$country_code]['states'] = $this->getStates(
136+
country_code: $country_code,
137+
translate: $translate
138+
);
139+
}
135140
}
136141

137-
return collect($this->countries);
142+
return collect($countries);
138143
}
139144

140145
public function getStates(

0 commit comments

Comments
 (0)