Laravel-mongodb: Call to a member function wrap() on a non-object when using Yajra datatables

Created on 24 Mar 2016  路  13Comments  路  Source: jenssegers/laravel-mongodb

I'm trying to use https://github.com/yajra/laravel-datatables with this MongoDB project. If I try to use the Eloquent or QueryBuilder, it causes FatalErrorException in QueryBuilderEngine.php line 96:
Call to a member function wrap() on a non-object.

The datatable works fine if I use a collection but with 7k records, processing becomes too slow.

Example
return Datatables::of(DB::collection('Sessions'))->make(true);

Thanks

Most helpful comment

<?php
namespace App;
use Closure;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Str;
use Yajra\Datatables\Helper;
use Yajra\Datatables\Request;
use Yajra\Datatables\Engines\QueryBuilderEngine;
class MongoQueryBuilderEngine extends QueryBuilderEngine
{
    public function __construct($model, Request $request)
    {
        parent::__construct($model->getQuery(), $request);
        $this->query      = $model;
        $this->query_type = 'eloquent';
    }
    public function count()
    {
        $myQuery = clone $this->query;
        return $myQuery->count();
    }
    public function paging()
    {
        $this->query->skip((int)$this->request['start'])
                    ->take((int) $this->request['length'] > 0 ? (int)$this->request['length'] : 10);
    }
}

use it with your query

new MongoQueryBuilderEngine($query, YRRequest::capture())
...... ->make(true);

All 13 comments

Have you tried with https://github.com/OpenSkill/Datatable/?

I use it with a couple of MongoDB tables and it works OK.

I'm have same error.
if use https://github.com/OpenSkill/Datatable/ <== collection get all: ex: User::all()

$this->connection->getQueryGrammar() is null

i'm try change code in line:
$row_count = $this->connection->getQueryGrammar()->wrap('row_count');
to
$row_count = "row_count";

it's work, but, total is 0. And paging do not work.

I think, problem is:
return $this->connection->table($this->connection->raw('(' . $myQuery->toSql() . ') count_row_table'))

in mongodb

select * from (select '1' as row_count from "posts") count_row_table

in Mysql

select * from (select '1' as row_count from posts) count_row_table

Show query:

(select '1' as row_count from "posts") count_row_table.aggregate([{"$group":{"aggregate":{"$sum":1},"_id":null}}],{"typeMap":{"root":"array","document":"array"}})

Any solution to this problem? Is there any trick to get data from mongodb server-side on datatable (https://github.com/yajra/laravel-datatables)?

I'm having the same issue, has anyone made any progress on this?

<?php
namespace App;
use Closure;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Str;
use Yajra\Datatables\Helper;
use Yajra\Datatables\Request;
use Yajra\Datatables\Engines\QueryBuilderEngine;
class MongoQueryBuilderEngine extends QueryBuilderEngine
{
    public function __construct($model, Request $request)
    {
        parent::__construct($model->getQuery(), $request);
        $this->query      = $model;
        $this->query_type = 'eloquent';
    }
    public function count()
    {
        $myQuery = clone $this->query;
        return $myQuery->count();
    }
    public function paging()
    {
        $this->query->skip((int)$this->request['start'])
                    ->take((int) $this->request['length'] > 0 ? (int)$this->request['length'] : 10);
    }
}

use it with your query

new MongoQueryBuilderEngine($query, YRRequest::capture())
...... ->make(true);

hai @marlborock can you explain where is YRRequest come from?

Oh, So you mean YRRequest is \Yajra\Datatables\Request. Ok got it.
Work perfectly...

Here how I use @marlborock script in my Moloquent Model:

$query = Permission::select('*');

$datatables = new MongoQueryBuilderEngine($query, \Yajra\Datatables\Request::capture());
return $datatables->make(true);

Fixed QuerySearch

    protected function compileQuerySearch($query, $column, $keyword, $relation = 'or')
    { 
        $query->orWhere(''.$column.'','like','%'.$keyword.'%');
    }

Hi,

I'm with problems in grid @fathur . When i tried create a grid, return this error:

(1/1) FatalThrowableError
Call to undefined method Yajra\Datatables\Request::capture()

Do you can i help?

$query = Permission::select('*');

$datatables = new MongoQueryBuilderEngine($query, \Yajra\Datatables\Request::capture());
return $datatables->make(true);

\Yajra\Datatables\Request::capture()
https://github.com/yajra/laravel-datatables cannot support version 7.5 +

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imrannazirbhat picture imrannazirbhat  路  3Comments

naveedyasin picture naveedyasin  路  3Comments

kschethan picture kschethan  路  3Comments

Vasiliy-Bondarenko picture Vasiliy-Bondarenko  路  3Comments

BlakeGardner picture BlakeGardner  路  3Comments