jeudi 14 septembre 2017

How Pass route() into datatables button like Edit and Delete

I have list table pegawai from DataTables and I have add edit and delete button into it but still static <a href="pegawai/view/'.$pegawais->id_pegawai.'" if user type manual and at the end there is / like example.com/pegawai/ it will become http://ift.tt/2h2Pla8} so I want use route() is it can ? because I've try it and just render string inside class tag

Here's my full DataTales code

public function data(Request $req)
    {
        DB::statement(DB::raw('set @rownum=0'));
        $pegawai = Pegawai::select(
            DB::raw('@rownum  := @rownum  + 1 AS rownum'),
            "pegawai.id_pegawai",
            "pegawai.nama",
            "pegawai.nip",
            "pegawai.id_jabatan",
            "pegawai.id_unit_kerja",
            "jabatan.nama_jabatan",
            "unit_kerja.nama_unit_kerja"
            )
        ->Join("jabatan","pegawai.id_jabatan","=","jabatan.id_jabatan")
        ->join("unit_kerja","pegawai.id_unit_kerja","=","unit_kerja.id_unit_kerja");

        $datatables = Datatables::of($pegawai)
            ->addColumn('action', function ($pegawais) {
                return '
                <a href="pegawai/view/'.$pegawais->id_pegawai.'" class="btn btn-sm btn-primary"><i class="fa fa-eye"></i></a>
                <a href="pegawai/edit/'.$pegawais->id_pegawai.'" class="btn btn-sm btn-warning"><i class="fa fa-edit"></i></a> 
                <a href="pegawai/delete/'.$pegawais->id_pegawai.'" class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></a>
                <a href="pegawai/cetak_data/'.$pegawais->id_pegawai.'" class="btn btn-sm btn-success"><i class="fa fa-print"></i></a>
                ';
            })
            ->editColumn('id_pegawai', '');

        if ($keyword = $req->get('search')['value']) {
            $datatables->filterColumn('rownum', 'whereRaw', '@rownum  + 1 like ?', ["%{$keyword}%"]);
        }

        return $datatables->make(true);
    }

How do I pass route() in DataTables like <a href=""



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire