vendredi 21 février 2020

Laravel Yajra DataTable Error if I added record more than 1

I've create datatatable with Yajra on Laravel, here I want to display data on the table, here is my source code :

$model = SaranaPrasaranaRuang::with('jenis_ruang')->where('dibuat_oleh',$this->user->id)->get();

        $dTable = Datatables()->of($model);
            $dTable = $dTable->addIndexColumn()
            ->editColumn('jenis_ruang',function($ruang){
                $jenis_ruang = $ruang->jenis_ruang->jenis_ruang;
                return $jenis_ruang;
            })
            ->editColumn('nama_ruang',function($data){
                return $data->nama_ruang;
            })
            ->addColumn('standard_prasarana',function($data){
                $btn = '<button class="btn btn-warning detail_prasarana" onclick=detailSarpras(this,'.$data->id_jenis_ruang.')>Lihat Standard Prasarana</button>';
                return $btn;
            })
            ->addColumn('standard_sarana',function($data){
                $btn = '<button class="btn btn-warning detail_sarana" onclick=detailSarpras(this,'.$data->id_jenis_ruang.')>Lihat Standard Sarana</button>';
                return $btn;
            })
            ->addColumn('action',function($data){
                $btn = "";
                $btn .= '<a href="/sarana_prasarana/ruang/edit/'.$data->id.'" class="btn btn-primary"><i class="fa fa-pencil"></i> Edit </a> ';
                $btn .= '<a href="/sarana_prasarana/ruang/delete/'.$data->id.'" class="btn btn-danger" onclick=return confirm("Apakah anda yakin ingin menghapus ?")><i class="fa fa-trash"></i> Hapus </a> ';
                $btn .= '<button class="btn btn-info" onclick=detailRuang('.$data->id.')><i class="fa fa-eye"></i> Detail</button>';
                return $btn;
            })
            ->rawColumns(['standard_prasarana','standard_sarana','action']);

        return $dTable->make(true);

My code above is working fine if my record only 1, but when I added one more record on my table , Datable give me response json like this :

"error": "Exception Message:\n\nUndefined index: "

I've try with eloquent(),query() but still didn't work

Anyone can help me out ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire