dikplhd/app/Imports/DatasetTable29Import.php

97 lines
3.1 KiB
PHP

<?php
namespace App\Imports;
use App\Models\Dataset\DatasetTable29;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
class DatasetTable29Import implements ToModel,WithStartRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
protected $datasetId;
protected $userId;
public function __construct($datasetId,$userId)
{
$this->datasetId = $datasetId;
$this->userId = $userId;
}
public function startRow(): int
{
return 6;
}
public function model(array $row)
{
// cek kalau row kosong jangan insert
if (
$row[0] === null &&
$row[1] === null &&
$row[2] === null &&
$row[3] === null &&
$row[4] === null &&
$row[5] === null &&
$row[6] === null &&
$row[7] === null &&
$row[8] === null &&
$row[9] === null &&
$row[10] === null &&
$row[11] === null &&
$row[12] === null &&
$row[13] === null &&
$row[14] === null &&
$row[15] === null &&
$row[16] === null &&
$row[17] === null &&
$row[18] === null &&
$row[19] === null &&
$row[20] === null &&
$row[21] === null &&
$row[22] === null &&
$row[23] === null &&
$row[24] === null &&
$row[25] === null &&
$row[26] === null
) {
return null; // baris kosong dilewati
}
return new DatasetTable29([
'dataset_id' => $this->datasetId,
'created_by' => $this->userId,
'nama_sungai' => $row[1],
'lokasi' => $row[2],
'titik_pantau' => $row[3],
'koordinat_lintang' => $row[4],
'koordinat_bujur' => $row[5],
'waktu_sampling' => $row[6],
'temperatur' => $row[7],
'ph' => $row[8],
'dhl' => $row[9],
'tds' => $row[10],
'tss' => $row[11],
'do' => $row[12],
'bod' => $row[13],
'cod' => $row[14],
'no2' => $row[15],
'no3' => $row[16],
'nh3' => $row[17],
'klorin_bebas' => $row[18],
'tp' => $row[19],
'fenol' => $row[20],
'minyak_lemak' => $row[21],
'detergen' => $row[22],
'fecal_coliform' => $row[23],
'total_coliform' => $row[24],
'sianida' => $row[25],
'h2s' => $row[26],
]);
}
}