protected function wrapWithRowCounter($originalQuery)
    {
        $tmpQuery = $originalQuery->cloneWithoutBindings(['where'])
            ->crossJoin(DB::raw('(SELECT @row := 0) as row_id_fake_table'));

        return DB::table(
            DB::raw("(SELECT *, (@row := @row+1) as {$this->idKey} FROM (" . $tmpQuery->toSql() . ") as t1) as t2")
        )->mergeBindings($originalQuery);
    }
protected function wrapWithRowCounter($originalQuery)
    {
        $tmpQuery = $originalQuery->cloneWithoutBindings(['where'])
            ->crossJoin(DB::raw('(SELECT @row := 0) as row_id_fake_table'));

        return DB::table(
            DB::raw("(SELECT *, (@row := @row+1) as {$this->idKey} FROM (" . $tmpQuery->toSql() . ") as t1) as t2")
        )->mergeBindings($originalQuery);
    }
protected function wrapWithRowCounter ( $ originalQuery ) { $ tmpQuery = $ originalQuery -> cloneWithoutBindings ( [ 'where' ] ) -> crossJoin ( DB :: raw ( '(SELECT @row := 0) as row_id_fake_table' ) ) ; return DB :: table ( DB :: raw ( "(SELECT *, (@row := @row+1) as {$this->idKey} FROM (" . $ tmpQuery -> toSql ( ) . ") as t1) as t2" ) ) -> mergeBindings ( $ originalQuery ) ; }
Add statement, which will include number of rows in original data set into query, which returns one page

@param EloquentBuilder|QueryBuilder $originalQuery Query, that retuns original data set to paginate
@return QueryBuilder
Add statement which will include number of rows in original data set into query which returns one page