Anons79 Mini Shell

Directory : /home/aplikasiposinfo/public_html/ppdb.samarinda.app/app/Imports/
Upload File :
Current File : /home/aplikasiposinfo/public_html/ppdb.samarinda.app/app/Imports/SekolahImport.php

<?php

namespace App\Imports;

use App\Models\Kelurahan;
use App\Models\Sekolah;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;


class SekolahImport implements ToCollection, WithCalculatedFormulas
{
    public function collection(Collection $rows)
    {
        foreach ($rows as $row => $data) 
        {
            $baris = $row + 1;
            $firstRow = $data[0];
            if(strtolower($firstRow) == 'no' || strtolower(trim($firstRow)) == ''){
                continue;
            }


            $findKelurahan = Kelurahan::where('nama_kelurahan', $data[6])->first();
            $findSekolah = Sekolah::where('npsn', $data[2])->first();
            if (!$findKelurahan) {
                dd($data);
            }
            if ($findSekolah) {
                $findSekolah->update([
                    'npsn' => $data[2],
                    'nama_sekolah' => $data[1],
                    'bentuk_pendidikan' => $data[3],
                    'status_sekolah' => $data[4],
                    'alamat' => $data[5],
                    'kelurahan_id' => $findKelurahan->id,
                    'lintang' => $data[8],
                    'bujur' => $data[9],
                ]);
            }else{
                Sekolah::create([
                    'npsn' => $data[2],
                    'nama_sekolah' => $data[1],
                    'bentuk_pendidikan' => $data[3],
                    'status_sekolah' => $data[4],
                    'alamat' => $data[5],
                    'kelurahan_id' => $findKelurahan->id,
                    'lintang' => $data[8],
                    'bujur' => $data[9],
                ]);
            }
        }
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]