1 | <?php |
||
2 | |||
3 | namespace Turahe\Master\Seeds; |
||
4 | |||
5 | use Illuminate\Database\Seeder; |
||
6 | use Turahe\Master\Models\City; |
||
7 | |||
8 | class CitiesTableSeeder extends Seeder |
||
9 | { |
||
10 | public function run() |
||
11 | { |
||
12 | $Csv = new CsvtoArray(); |
||
13 | $file = __DIR__.'/../../resources/csv/cities.csv'; |
||
14 | $header = ['id', 'province_id', 'name', 'lat', 'long']; |
||
15 | $data = $Csv->csv_to_array($file, $header); |
||
16 | $cities = array_map(function ($arr) { |
||
17 | return [ |
||
18 | 'state_id' => $arr['province_id'], |
||
19 | 'name' => $arr['name'], |
||
20 | 'latitude' => $arr['lat'], |
||
21 | 'longitude' => $arr['long'], |
||
22 | 'created_at' => now()->toDateTimeString(), |
||
23 | 'updated_at' => now()->toDateTimeString(), |
||
24 | ]; |
||
25 | }, $data); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
26 | |||
27 | City::insert($cities); |
||
28 | } |
||
29 | } |
||
30 |