69 lines
2.3 KiB
PHP
69 lines
2.3 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) {
|
|
return null; // baris kosong dilewati
|
|
}
|
|
return new DatasetTable29([
|
|
'dataset_id' => $this->datasetId,
|
|
'created_by' => $this->userId,
|
|
'nama_sungai' => $row[0],
|
|
'lokasi' => $row[1],
|
|
'titik_pantau' => $row[2],
|
|
'koordinat_lintang' => $row[3],
|
|
'koordinat_bujur' => $row[4],
|
|
'waktu_sampling' => $row[5],
|
|
'temperatur' => $row[6],
|
|
'ph' => $row[7],
|
|
'dhl' => $row[8],
|
|
'tds' => $row[9],
|
|
'tss' => $row[10],
|
|
'do' => $row[11],
|
|
'bod' => $row[12],
|
|
'cod' => $row[13],
|
|
'no2' => $row[14],
|
|
'no3' => $row[15],
|
|
'nh3' => $row[16],
|
|
'klorin_bebas' => $row[17],
|
|
'tp' => $row[18],
|
|
'fenol' => $row[19],
|
|
'minyak_lemak' => $row[20],
|
|
'detergen' => $row[21],
|
|
'fecal_coliform' => $row[22],
|
|
'total_coliform' => $row[23],
|
|
'sianida' => $row[24],
|
|
'h2s' => $row[25],
|
|
]);
|
|
}
|
|
}
|