Laravel-datatables: DataTables with Jenssengers MongoDB package

Created on 29 Apr 2018  路  4Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request

I am trying to get data from a mongodb database using Jenssengers Laravel MongoDB package but constantly hits an error.

Type error: Argument 1 passed to Illuminate\Database\Query\Builder::setBindings() must be of the type array, object given, called in /vendor/yajra/laravel-datatables-oracle/src/QueryDataTable.php on line 135 in vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2291

Code snippet of problem

$store = Store::where('user_id', Auth::user()->id)->first(); $query = Product::with(['branch'])->where('store_id', '=', $store->id); return datatables()->eloquent($query)->toJson();

System details

Ubuntu 16.04 LTS PHP 7.1 Laravel 5.4 DataTables 8.0

MongoDB question

Most helpful comment

I redefined \Yajra\DataTables\EloquentDataTable :

namespace App\DataTables;

use Jenssegers\Mongodb\Eloquent\Builder;

class EloquentDataTable extends \Yajra\DataTables\EloquentDataTable
{
    public function count()
    {
        /** @var Builder $builder */
        $builder = $this->prepareCountQuery();
        $table   = $this->connection->raw('(' . $builder->toSql() . ') count_row_table');

        return $this->connection->table($table)
            ->setBindings($builder->getQuery()->getBindings())
            ->count();
    }
}

All 4 comments

I redefined \Yajra\DataTables\EloquentDataTable :

namespace App\DataTables;

use Jenssegers\Mongodb\Eloquent\Builder;

class EloquentDataTable extends \Yajra\DataTables\EloquentDataTable
{
    public function count()
    {
        /** @var Builder $builder */
        $builder = $this->prepareCountQuery();
        $table   = $this->connection->raw('(' . $builder->toSql() . ') count_row_table');

        return $this->connection->table($table)
            ->setBindings($builder->getQuery()->getBindings())
            ->count();
    }
}

Solved

above solution solved my issue. my code >

<?php

namespace YajraDataTables;
use JenssegersMongodbEloquentBuilder;
//use IlluminateDatabaseEloquentBuilder;
use YajraDataTablesExceptionsException;
use IlluminateDatabaseEloquentRelationsRelation;
use IlluminateDatabaseEloquentRelationsBelongsTo;
use IlluminateDatabaseEloquentRelationsHasOneOrMany;
use IlluminateDatabaseEloquentRelationsBelongsToMany;

class EloquentDataTable extends QueryDataTable
{
public function count()
{
/** @var Builder $builder */
$builder = $this->prepareCountQuery();
$table = $this->connection->raw('(' . $builder->toSql() . ') count_row_table');

    return $this->connection->table($table)
        ->setBindings($builder->getQuery()->getBindings())
        ->count();
}

}``

features doesn't work . cant sort or search with mongodb only

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmadbadpey picture ahmadbadpey  路  3Comments

ghost picture ghost  路  3Comments

vipin733 picture vipin733  路  3Comments

Mopster picture Mopster  路  3Comments

kamrava picture kamrava  路  3Comments