File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Eclipse \World \Seeders ;
4+
5+ use Eclipse \World \Models \Currency ;
6+ use Illuminate \Database \Seeder ;
7+
8+ class CurrencySeeder extends Seeder
9+ {
10+ /**
11+ * Run the database seeds.
12+ */
13+ public function run (): void
14+ {
15+ $ currencies = [
16+ [
17+ 'id ' => 'EUR ' ,
18+ 'name ' => 'Euro ' ,
19+ 'is_active ' => true ,
20+ ],
21+ [
22+ 'id ' => 'USD ' ,
23+ 'name ' => 'US Dollar ' ,
24+ 'is_active ' => true ,
25+ ],
26+ [
27+ 'id ' => 'GBP ' ,
28+ 'name ' => 'British Pound ' ,
29+ 'is_active ' => true ,
30+ ],
31+ ];
32+
33+ foreach ($ currencies as $ currency ) {
34+ Currency::firstOrCreate (
35+ ['id ' => $ currency ['id ' ]],
36+ $ currency
37+ );
38+ }
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Eclipse \World \Seeders ;
4+
5+ use Illuminate \Database \Seeder ;
6+
7+ class WorldSeeder extends Seeder
8+ {
9+ public function run (): void
10+ {
11+ $ this ->call (CurrencySeeder::class);
12+ }
13+ }
Original file line number Diff line number Diff line change 77use Eclipse \World \Models \Region ;
88use Exception ;
99use Illuminate \Support \Carbon ;
10+ use Illuminate \Support \Facades \Http ;
1011
1112class ImportCountries extends QueueableJob
1213{
@@ -23,10 +24,16 @@ protected function execute(): void
2324 $ existingCountries = Country::withTrashed ()->get ()->keyBy ('id ' );
2425
2526 // Load new country data
26- $ countries = json_decode (file_get_contents ('https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json ' ), true );
27+ $ response = Http::get ('https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json ' );
28+
29+ if (! $ response ->successful ()) {
30+ throw new Exception ('Failed to fetch countries data: ' .$ response ->status ());
31+ }
32+
33+ $ countries = $ response ->json ();
2734
2835 if (! $ countries ) {
29- throw new Exception ('Failed to fetch or parse countries data ' );
36+ throw new Exception ('Failed to parse countries data ' );
3037 }
3138
3239 foreach ($ countries as $ rawData ) {
Original file line number Diff line number Diff line change 55use Eclipse \Common \Foundation \Jobs \QueueableJob ;
66use Eclipse \World \Models \Currency ;
77use Exception ;
8+ use Illuminate \Support \Facades \Http ;
89
910class ImportCurrencies extends QueueableJob
1011{
@@ -18,10 +19,16 @@ protected function execute(): void
1819 $ existingCurrencies = Currency::withTrashed ()->get ()->keyBy ('id ' );
1920
2021 // Load new currency data from REST Countries API
21- $ countries = json_decode (file_get_contents ('https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json ' ), true );
22+ $ response = Http::get ('https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json ' );
23+
24+ if (! $ response ->successful ()) {
25+ throw new Exception ('Failed to fetch countries data: ' .$ response ->status ());
26+ }
27+
28+ $ countries = $ response ->json ();
2229
2330 if (! $ countries ) {
24- throw new Exception ('Failed to fetch or parse countries data ' );
31+ throw new Exception ('Failed to parse countries data ' );
2532 }
2633
2734 $ processedCurrencies = [];
You can’t perform that action at this time.
0 commit comments