Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88150

Update Data with Mat-website EXCEL , If column doesn't exist insert NULL, But if column exists insert value EXCEL

$
0
0

I have a problem, I want to update data using Mat website EXCEL laravel, I give condition like this.

  1. enter image description here

Be there excel line called Bujur and Lintang, When the Line is filled will insert to column DB like This

enter image description here

but when Line Bujur and Lintang Not Exists in Excel like this

enter image description here

Column bujur and lintang ini Database will fill NULL value,

when i removed line Lintang and Bujur in EXCEL value bujur and lintang in DB is true fill NULL value, As Expected

the problem here

When I fill Bujur and Lintang in EXCEL, value insert to database keep NULL, same as like I removed Lintang and Bujur in EXCEL,

This is my code

  $notExists = array_key_exists('Lintang', $row ) || array_key_exists('Bujur', $row);
            if($notExists == FALSE){
                 Pribadi::updateOrCreate([
                'sekolah_id'    => $sekolah_id,
                'siswa_id'      => $siswa->id,
            ],
            [
                'sekolah_id'        => $sekolah_id,
                'siswa_id'          => $siswa->id,
                'nipd'              => $row['NIPD'],
                'jenis_tinggal'     => $row['Jenis Tinggal'],
                'alat_transportasi' => $row['Alat Transportasi'],
                'lintang'           => NULL,
                'bujur'             => NULL,

            ]);
        }
        elseif($notExists == TRUE){

           Pribadi::updateOrCreate([
                'sekolah_id'    => $sekolah_id,
                'siswa_id'      => $siswa->id,
            ],
            [
                'sekolah_id'        => $sekolah_id,
                'siswa_id'          => $siswa->id,
                'nipd'              => $row['NIPD'],
                'jenis_tinggal'     => $row['Jenis Tinggal'],
                'alat_transportasi' => $row['Alat Transportasi'],
                'lintang'           => $row['Lintang'],
                'bujur'             => $row['Bujur'],

            ]);
             }

the code is when column exists is FALSE( Column and line EXCEL not EXIST) is insert NULL, but when column exists is TRUE( Column and line EXCEL is EXIST) is inserted a value,

but when I fill the column Lintang and Bujur in EXCEL, the value keeps return NULL!

what's wrong in my code? Thanks for your helping.


Viewing all articles
Browse latest Browse all 88150

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>