Home > Software engineering >  How to retrive from other table and input it again into another table in laravel?
How to retrive from other table and input it again into another table in laravel?

Time:11-06

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);
}

CodePudding user response:

Yup, I finally got it, the problem is on my model.

$nama_karyawan = DB::table('tbl_karyawan')->where($data)->value('Nama_kyn');
$nipkyn = DB::table('tbl_karyawan')->where($data)->value('Nip_kyn');

I just change 'get' to 'value'.

  • Related