22
33declare (strict_types = 1 );
44
5- namespace Wame \Address \Fields ;
5+ namespace Wame \LaravelNovaAddressField \Fields ;
66
77use Exception ;
88use Illuminate \Support \Str ;
99use Laravel \Nova \Fields \Field ;
1010use Laravel \Nova \Fields \SupportsDependentFields ;
11- use Wame \Address \Casts \AddressCast ;
12- use Wame \LaravelNovaCountry \Enums \CountryStatusEnum ;
13- use Wame \LaravelNovaCountry \Models \Country ;
11+ use Rinvex \Country \CountryLoader ;
12+ use Wame \LaravelNovaAddressField \Casts \AddressCast ;
1413
1514class Address extends Field
1615{
@@ -23,7 +22,7 @@ class Address extends Field
2322 */
2423 public $ component = 'address ' ;
2524
26- protected $ dependentShouldEmitChangesEvent = true ;
25+ protected ? bool $ dependentShouldEmitChangesEvent = true ;
2726
2827 public function __construct ($ name , $ attribute = null , callable $ resolveCallback = null )
2928 {
@@ -129,37 +128,20 @@ public function withPhone(): Address
129128 }
130129
131130 /**
132- * @return array|mixed|mixed[]
133- * @throws \JsonException
131+ * @return array
132+ * @throws \Rinvex\Country\CountryLoaderException
134133 */
135- private function getCountryList (): mixed
134+ private function getCountryList (): array
136135 {
137- $ version = $ this -> getCountryPackageVersion () ;
136+ $ return = [] ;
138137
139- if (Str::startsWith ($ version , '2. ' )) {
140- return Country::query ()->where (['status ' => CountryStatusEnum::ENABLED ])->orderBy ('title ' )->pluck ('title ' , 'id ' )->toArray ();
138+ $ list = CountryLoader::countries ();
139+ foreach ($ list as $ item ) {
140+ $ country = country ($ item ['iso_3166_1_alpha2 ' ]);
141+
142+ $ return [$ country ->getIsoAlpha2 ()] = $ country ->getName ();
141143 }
142144
143- return Country::query ()->where (['status ' => Country::STATUS_ENABLED ])->orderBy ('title ' )->pluck ('title ' , 'code ' )->toArray ();
144- }
145-
146- /**
147- * @return mixed
148- * @throws \JsonException
149- * @throws Exception
150- */
151- public function getCountryPackageVersion (): mixed
152- {
153- $ composerLockFile = base_path ('composer.lock ' );
154- $ packageName = 'wamesk/laravel-nova-country ' ;
155- $ composerData = json_decode (file_get_contents ($ composerLockFile ), true , 512 , JSON_THROW_ON_ERROR );
156-
157- foreach ($ composerData ['packages ' ] as $ package ) {
158- if ($ package ['name ' ] === $ packageName ) {
159- return $ package ['version ' ];
160- }
161- }
162-
163- throw new Exception ('Package ' . $ packageName . 'not found ' );
145+ return $ return ;
164146 }
165147}
0 commit comments