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