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