lundi 1 novembre 2021

How to retrive from other table and input it again into another table in laravel?

I want to retrieve some data from 'tbl_karyawan' and input into 'tbl_absen' which is if the NIP exist from 'tbl_karyawan' then parshing some data into 'tbl_absen'. I was create the code, and the data is going well. but i have something trouble with tbl_absen

i want the data input in Nip_kyn be like 'KIP001' not [{"Nip_kyn":"KIP001"}].

this is my Model

 public function presensi($data)
{
    $isExist = DB::table('tbl_karyawan')
        ->where('Nip_kyn', $data)->exists();

    if ($isExist) {

        
        $namakyn = DB::table('tbl_karyawan')->where($data)->get('Nama_kyn');
        $nippppp = DB::table('tbl_karyawan')->where($data)->select('Nip_kyn')->get($data);

        $values = array('Nip_kyn' => $nippppp, 'Nama_kyn' => $namakyn, 'Jam_msk' => now(), 'Log_date' => today());
        DB::table('tbl_absen')->insert($values);
    } else {
        echo 'data not available';
    }
}

this is my controller

public function get()
{
    $day = [
        'time_in' => $this->AbsenModel->timeIN(),
        'time_out' => $this->AbsenModel->timeOut(),
        'break' => $this->AbsenModel->break(),
        // absen here
        's' => $this->AbsenModel->absensi(),
    ];

    $data = [
        'Nip_kyn' => Request()->Nip_kyn,
    ];
    $this->AbsenModel->presensi($data);

    return view('v_absen', $data, $day);
}



Aucun commentaire:

Enregistrer un commentaire