|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Turahe\Master\Seeds; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Seeder; |
|
6
|
|
|
use Turahe\Master\Models\Country; |
|
7
|
|
|
|
|
8
|
|
|
class CountriesTableSeeder extends Seeder |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Run the database seeds. |
|
12
|
|
|
* |
|
13
|
|
|
* @return void |
|
14
|
|
|
*/ |
|
15
|
|
|
public function run() |
|
16
|
|
|
{ |
|
17
|
|
|
$file = __DIR__.'/../../resources/countries.json'; |
|
18
|
|
|
$data = json_decode(file_get_contents($file), true); |
|
19
|
|
|
$countries = array_map(function ($country) { |
|
20
|
|
|
return [ |
|
21
|
|
|
'capital' => $country['capital'] ?? null, |
|
22
|
|
|
'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null), |
|
23
|
|
|
'country_code' => $country['country-code'], |
|
24
|
|
|
'currency' => ((isset($country['currency'])) ? $country['currency'] : null), |
|
25
|
|
|
'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null), |
|
26
|
|
|
'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null), |
|
27
|
|
|
'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null), |
|
28
|
|
|
'iso_3166_2' => $country['iso_3166_2'], |
|
29
|
|
|
'iso_3166_3' => $country['iso_3166_3'], |
|
30
|
|
|
'name' => $country['name'], |
|
31
|
|
|
'region_code' => (isset($country['region-code'])) ? $country['region-code'] : null, //$country['region-code'], |
|
32
|
|
|
'sub_region_code' => (isset($country['sub-region-code'])) ? $country['sub-region-code'] : null, //$country['sub-region-code'], |
|
33
|
|
|
'eea' => (bool) $country['eea'], |
|
34
|
|
|
'calling_code' => $country['calling_code'], |
|
35
|
|
|
'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null), |
|
36
|
|
|
'flag' =>((isset($country['flag'])) ? $country['flag'] : null), |
|
37
|
|
|
'created_at' => now()->toDateTimeString(), |
|
38
|
|
|
'updated_at' => now()->toDateTimeString(), |
|
39
|
|
|
]; |
|
40
|
|
|
}, $data); |
|
41
|
|
|
|
|
42
|
|
|
Country::insert($countries); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|