문제

I have the following simple controller:

class OrdersController extends \BaseController {

    public function index()
    {
        $orders = Order::all();

        return Datatables::of($orders)->make();
    }
}

Trying to use the bllim DataTables package to output my tables. When I can DataTables above, I get this error:

Call to undefined method Illuminate\Database\Eloquent\Collection::getQuery()

The error is located in \Bllim\Datatables\Datatables.php on the line:

$this->columns = $this->query_type == 'eloquent' ? $this->query->getQuery()->columns : $this->query->columns;

This method should be defined, unless I am mistaken. So what is missing here?

도움이 되었습니까?

해결책

Usage

It is very simple to use this bundle. Just create your own fluent query object or eloquent object without getting results (that means don't use get(), all() or similar methods) and give it to Datatables. You are free to use all Eloquent ORM and Fluent Query Builder features.

By calling the all() method you are returning an Illuminate\Database\Eloquent\Collection object which in this case doesn't contain the getQuery() method, you need to pass a Illuminate\Database\Eloquent\Builder or Illuminate\Database\Query\Builder instead.

Try this:

return Datatables::of(Order::select(array('id', 'othercolumns')))->make();

Or this:

$query = DB::table('orders')->select(array('id','othercolumns'));
return Datatables::of($query)->make();

Select the columns you want to show in the data table in the array.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top