Specific Method in Laravel5.4 Yajra Datatable

42 views Asked by At

When I'm using the normal Query of datatable it perfectly works,

public function getHmoDatatable()
{
    $Hmo = Hmo::query();
   return Datatables::eloquent($Hmo)
    ->addColumn('action', function($row) {
        return '<a href="/hmo/principal/'. $row->id .'/edit" class="btn btn-primary">Update</a>';
    })
   ->make(true);
}

But when I'm using specific query like this attached, it doesnt work

public function getHmoPendingDatatable()
{
    $Hmo = Hmo::getHmoPending();
   return Datatables::eloquent($Hmo)
    ->addColumn('action', function($row) {
        return '<a href="/hmo/principal/pending'. $row->id .'/edit" class="btn btn-primary">Update</a>';
    })
   ->make(true);
}
1

There are 1 answers

0
Martney Acha On

What I did was follow the new way of https://github.com/yajra/laravel-datatables You can use whatever you need

return datatables()->of(User::query())->toJson();
return datatables()->of(DB::table('users'))->toJson();
return datatables()->of(User::all())->toJson();

return datatables()->eloquent(User::query())->toJson();
return datatables()->queryBuilder(DB::table('users'))->toJson();
return datatables()->collection(User::all())->toJson();

return datatables(User::query())->toJson();
return datatables(DB::table('users'))->toJson();
return datatables(User::all())->toJson();

Here is my Code

 public function getHmoPendingDatatable()
    {
        return datatables()->of(Hmo::getHmoPending())
        ->addColumn('action', function($row) {
            return '<a href="/hmo/principal/'. $row->id .'/edit" class="btn btn-primary">Update</a>';
        })
       ->make(true);
    }