<?php

namespace Database\Seeders;

use App\Models\KelompokKategoriPivot;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class KelompokKategoriPivotSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $csvFile = fopen(base_path("database/seeders/data_csv/kelompok_kategori_pivot.csv"), "r");

        $firstline = true;
        while (($data = fgetcsv($csvFile, 2000, ",")) !== FALSE) {
            if (!$firstline) {
                KelompokKategoriPivot::create([
                    'kelompok_kategori_id' => $data['0'] ?? '',
                    "produk_id" => $data['1'] ?? ''
                ]);
            }
            $firstline = false;
        }
    }
}
