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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With