mercredi 18 octobre 2017

How to make a date/time count like facebook (3days ago, etc)

I'm a newbie in php, and offcourse I'm a newbie in laravel. Anyway, 've got a problem. In some documentations, people uses "diffForHuman". Unfortunately I always get error 500 when I use it. I want to do a count of date/time like facebook, ex : "3days ago", etc.

this is my controller :

    public function show(Request $request)
{
 if($request->ajax()){
        $searchs = $request->get('search');
        $search = $searchs['value'];
        \DB::statement(\DB::raw('set @nomor = 0'));

        $index = DB::table('tb_jabatan_karyawan')
                ->leftJoin('tb_jabatan','tb_jabatan.id','=','tb_jabatan_karyawan.id_jabatan')
                ->leftJoin('tb_karyawan','tb_karyawan.id','=','tb_jabatan_karyawan.id_karyawan')
                ->select([
                    \DB::raw('@nomor := @nomor + 1 as no'),

                    'tb_jabatan_karyawan.id as id',
                    'tb_jabatan_karyawan.id_karyawan as id_karyawan',
                    'tb_jabatan_karyawan.id_jabatan as id_jabatan',
                    'tb_karyawan.nama as nama',
                    'tb_karyawan.status_karyawan as status',
                    'tb_jabatan.nama_jabatan as jabatan',
                    'tb_karyawan.tgl_masuk as lama'
                    ]);
            //dd(Carbon::parse($index->lama)->diffForHumans());
        return Datatables::of($index)
            ->edit_column('no', function($index){
                return '<center>'.$index->no.'</center>';
            })
            ->edit_column('nama', function($index){
                return ucwords($index->nama);
            })
            ->edit_column('status', function($index){
                return ucwords($index->status);
            })
            ->editColumn('lama', function ($index) {
            return $index->lama->diffForHumans();
            })
            ->filter(function ($query) use ($request){
                if ($request->get('search')['value']){
                  $query->where('nama', 'like', "%{$request->get('search')['value']}%");
                }
            })
            ->addColumn('action', function($index){
                $tag = "<center><a class='btn btn-info btn-xs' onclick=atur('".$index->id_karyawan."','".$index->id_jabatan."')><i class='fa fa-pencil'></i> Proses</a></center>";
                return $tag;
            })
        ->make(true);
    }

}

and this is my datatable :

    function getData(){
table = $('#table').DataTable({
    dom: "lBfrtip",
    processing: true,
    serverSide: true,
    destroy: true,
    bFilter:true,
    searching: true,
    order: [],
    ajax: base_adm+'kelola/pengunduran-karyawan/show',

    columns: [
        {data: 'no', name: 'no', orderable: true, searchable: false},
        {data: 'nama', name: 'nama', orderable: true, searchable: true},
        {data: 'status', name: 'status', orderable: true, searchable: false},
        {data: 'jabatan', name: 'jabatan', orderable: true, searchable: false},
        {data: 'lama', name: 'lama', orderable: true, searchable: false},
        {data: 'action', name: 'action', orderable: false, searchable: false},
    ],
      "language": {
        "lengthMenu": " _MENU_  Baris",
        "zeroRecords": "Data Tidak Tersedia",
        "info": "Halaman _PAGE_ Dari _PAGES_",
        "infoEmpty": "Data Tidak Tersedia",
        "infoFiltered": "(Hasil penyaringan dari _MAX_ total data)",
        "sSearch": "Pencarian ",
        "oPaginate": {
        "sNext" : "Selanjutnya",
        "sPrevious" : "Sebelumnya",
    },
    },
});

}

I hope someone will help me to fix this. thank's anyway



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire