Skip to content

Commit db6f595

Browse files
authored
Merge pull request yajra#632 from standaniels/patch-2
Unset any bindings to select statement
2 parents 599aab0 + 1cc919d commit db6f595

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/yajra/Datatables/Datatables.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,17 @@ private function count()
332332
if ( ! Str::contains(Str::lower($myQuery->toSql()), ['union', 'having', 'distinct'])) {
333333
$myQuery->select($this->connection->raw("'1' as row_count"));
334334
}
335+
336+
if ($myQuery instanceof QueryBuilder) {
337+
$bindings = $myQuery->getRawBindings();
338+
} else {
339+
$bindings = $myQuery->getQuery()->getRawBindings();
340+
}
341+
unset($bindings['select']);
342+
$bindings = array_flatten($bindings);
335343

336344
return $this->connection->table($this->connection->raw('(' . $myQuery->toSql() . ') count_row_table'))
337-
->setBindings($myQuery->getBindings())->count();
345+
->setBindings($bindings)->count();
338346
}
339347

340348
/**

tests/DatatablesBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected function setupBuilder($showAllRecords = false)
199199
$builder->getConnection()->shouldReceive('raw')->andReturn('(select id, name from users) count_row_table');
200200
$builder->shouldReceive('select')->once()->andReturn($builder);
201201
$builder->getConnection()->shouldReceive('table')->times(2)->andReturn($builder);
202-
$builder->shouldReceive('getBindings')->times(2)->andReturn(array());
202+
$builder->shouldReceive('getRawBindings')->times(2)->andReturn(array());
203203
$builder->shouldReceive('setBindings')->times(2)->with(array())->andReturn($builder);
204204
if ( ! $showAllRecords) {
205205
$builder->shouldReceive('skip')->once()->andReturn($builder);

0 commit comments

Comments
 (0)