Level 1
any one is there
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I get following error in Yajra Datatables in google chrome develper tool
BadMethodCallException Method getQuery does not exist.
code: <?php
namespace App\DataTables;
use App\Staff; use App\CompanyGroup; use Yajra\Datatables\Services\DataTable; use DB;
class EmpDataTable extends DataTable {
/**
* Build DataTable class.
*
* @return \Yajra\Datatables\Engines\BaseEngine
*/
public function ajax()
{
return $this->datatables->eloquent($this->query())
->addColumn('name',function($staffs) {
return $staffs->firstname;
})
->addColumn('lastname',function($staffs) {
return $staffs->lastname;
})
->make(true);
}
/**
* Get the query object to be processed by dataTables.
*
* @return mixed
*/
public function query()
{
$query = Staff::get();
//$query = DB::table('staffs')->get();
return $this->applyScopes($query);
}
/**
* Optional method if you want to use html builder.
*
* @return \Yajra\Datatables\Html\Builder
*/
public function html()
{
return $this->builder()
->columns([
'name',
'lastname'
])
->addAction(['width' => '130px']);
}
}
?>
Please or to participate in this conversation.