Skip to content

Commit b62ea1d

Browse files
Using column names instead of raw queries to filter and order
1 parent 58b3f3a commit b62ea1d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ If you are familiar with eloquent and would like to use it in combination with [
1010

1111
### Step 2: Add DataTables javascript and set it up
1212
For more information check out the [datatables manual](http://datatables.net/manual/index).
13+
Make sure you have [csrf requests](http://laravel.com/docs/master/routing#csrf-protection) working with jquery ajax calls.
1314
```javascript
1415
var table = $('#example').DataTable({
1516
"processing": true,

src/LiveControl/EloquentDataTable/DataTable.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,19 @@ private function addAllFilter($search)
243243
{
244244
$this->builder = $this->builder->where(
245245
function ($query) use ($search) {
246-
foreach ($this->rawColumns as $rawColumn) {
247-
$query->orWhere(new raw($rawColumn), 'like', '%' . $search . '%');
246+
foreach ($this->columnNames as $column) {
247+
$query->orWhere($column, 'like', '%' . $search . '%');
248248
}
249249
}
250250
);
251251
}
252252

253253
private function addColumnFilters()
254254
{
255-
foreach ($this->rawColumns as $i => $rawColumn) {
255+
foreach ($this->columnNames as $i => $column) {
256256
if ( static::$versionTransformer->isColumnSearched($i) ) {
257257
$this->builder->where(
258-
new raw($rawColumn),
258+
$column,
259259
'like',
260260
'%' . static::$versionTransformer->getColumnSearchValue($i) . '%'
261261
);
@@ -267,9 +267,9 @@ protected function addOrderBy()
267267
{
268268
if ( static::$versionTransformer->isOrdered() ) {
269269
foreach (static::$versionTransformer->getOrderedColumns() as $index => $direction) {
270-
if ( isset($this->rawColumns[$index]) ) {
270+
if ( isset($this->columnNames[$index]) ) {
271271
$this->builder->orderBy(
272-
new raw($this->rawColumns[$index]),
272+
$this->columnNames[$index],
273273
$direction
274274
);
275275
}

0 commit comments

Comments
 (0)