Kenapa data yang muncul dari hasil relasi undefined

Saya ingin manampilkan data status tetapi ketika muncul undefined data status tersebut diambil dari relasi jadi relasinya di tabel list_asset memiliki nama id_pelepasanstatus nah id_pelepasanstatus tersebut di relasikan ke tabel pelepasanstatus_asset ke id_pelepasanstatus nah sedangkan yang ingin dimunculkan itu desc_pelepasanstatus yang terdapat di pelepasanstatus_asset

ajax

$(document).ready(function (e) {
    var table = $("#table1_test").DataTable();
    $('#previewButton').on('click', function () {
        var tglawal = $('#tglawal_pre').val();
        var tglakhir = $('#tglakhir_pre').val();
        // dateControl.value = '2017-06-01';
        let url = "{{ route('previewPertanggal', ['tglawal' => ':post_id', 'tglakhir' => ':vote']) }}";
        url = url.replace(':post_id', tglawal);
        url = url.replace(':vote', tglakhir);
        $.ajax({
            type: 'GET',
            url: url,
            success: function (data) {
                // console.log(data);
                // Update the table with the new data
                table.destroy();
                $('.refresh').remove();
                for (let index = 0; index < data['success'].length; index++) {
                    // const element = data[index];
                    var nomor = index + 1
                    var foto_aset = '<td><img id="foto_aset" src="' + data['success'][index]['foto_aset'] + '"  width="40" height="40"></td>';

                    $('#isi_data').append('<tr class="refresh"><td>' +
                        nomor + '</td><td>' + data['success'][index]['kode_aset'] +
                        '</td><td>' +
                        data['success'][index]['satuan']['nama_satuan'] + '</td><td>' +
                            data['success'][index]['list_asset']?.['id_pelepasanstatus']+ '</td><td>' +
                        data['success'][index]['tgl_beli'] + '</td><td>' +
                        data['success'][index]['tgl_pakai'] + '</td><td>' +
                        data['success'][index]['harga_perolehan'] + '</td><td>' +
                        data['success'][index]['metode'] + '</td><td>' +
                        data['success'][index]['umur'] + '</td><td>' +
                        data['success'][index]['supplier']['nama_supplier'] + '</td><td>' +
                        data['success'][index]['keterangan'] + '</td><td>' +
                        data['success'][index]['no_faktur'] + '</td><td>' +
                        data['success'][index]['nama_aset'] + '</td><td>' +
                        // data['success'][index]['jabatan']['desc_jabatan'] + '</td><td>' +
                        data['success'][index]['departement']['nama_departement'] + '</td><td>' +
                        data['success'][index]['lokasi'] + '</td><td>' +
                        foto_aset + '</td><td>' +
                        data['success'][index]['persentase'] + '</td><td>' +
                        data['success'][index]['tarif'] + '</td></tr>');

                }
                table = $("#table1_test").DataTable();
                // $('#quoteFormPreview').modal().hide();
                // $("#quoteFormPreview .

            },
            error: function (xhr, status, error) {
                // Handle the error
                console.log(error);
            }
        });
    });

});

Controller

public function previewPertanggal($tglawal, $tglakhir)
    {
         //dd("sadasdadadada");
         //dd($tglakhir);
        $pelepasan = DB::table('pelepasanstatus_asset')->get();
        $satuan = DB::table('satuan')->where('status_satuan','=','1')->get();
        $supplier = DB::table('supplier')->where('status_supplier','=','1')->get();
        $groupasset = DB::table('group_asset')->where('status_grup_asset','=','1')->get();
        $datakaryawan = DB::table('data_karyawan')->where('status_data_karyawan','=','1')->get();
        $departement = DB::table('departement')->where('status','=','1')->get();
        $listasset = DB::table('list_asset')->where('id_pelepasanstatus','=','1')->get();
        $listasset = DB::table('list_asset')
        ->leftjoin('pelepasanstatus_asset', 'list_asset.id_pelepasanstatus', '=', 'pelepasanstatus_asset.id_pelepasanstatus')
        ->leftjoin('satuan', 'list_asset.id_satuan', '=', 'satuan.id_satuan')
        ->leftjoin('supplier', 'list_asset.id_supplier', '=', 'supplier.id_supplier')
        ->leftjoin('group_asset', 'list_asset.id_grup', '=', 'group_asset.id_grup')
        ->leftjoin('data_karyawan', 'list_asset.id_karyawan', '=', 'data_karyawan.id_karyawan')
        ->leftjoin('departement', 'list_asset.id_departement', '=', 'departement.id_departement')
        ->leftjoin('jabatan', 'data_karyawan.id_jabatan', '=', 'jabatan.id_jabatan')
        ->whereBetween('list_asset.created_at',[$tglawal, $tglakhir])
        ->select('list_asset.*', 'satuan.nama_satuan', 'supplier.nama_supplier', 'group_asset.nama_grup_aset', 'jabatan.desc_jabatan', 'departement.nama_departement', 'data_karyawan.nama_karyawan','pelepasanstatus_asset.desc_pelepasanstatus')
        ->get();
        $previewtanggal = listAsset::with('satuan', 'supplier', 'departement', 'pelepasan')
    ->whereBetween('created_at', [$tglawal, $tglakhir])
    ->get();
        return response()->json(['success'=>$previewtanggal, 'status' => 1]);


}

Model statusPelepasan

     public function listAsset()
    {
        return $this->hasMany(listAsset::class);
    }

Model listAsset

 public function pelepasan()
    {
        return $this->belongsTo(statusPelepasan::class, 'id_pelepasanstatus');
    }
avatar zkdlinnn
@zkdlinnn

10 Kontribusi 2 Poin

Dipost 1 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban