Bllim data tables in Laravel 4 throws an undefined getQuery () exception

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 data 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 in \Bllim\Datatables\Datatables.phpthe line:

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

This method should be defined if I am not mistaken. So what's missing here?

+4
source share
1 answer

Using

. ( get(), all() ) Datatables. Eloquent ORM Fluent Query Builder.

all(), Illuminate\Database\Eloquent\Collection, getQuery(), Illuminate\Database\Eloquent\Builder Illuminate\Database\Query\Builder.

:

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

:

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

, .

+8

Source: https://habr.com/ru/post/1538245/


All Articles