Skip to content

Commit db060d4

Browse files
committed
#3010 - convert expressions to strings
1 parent cd684c1 commit db060d4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/EloquentDataTable.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
1111
use Illuminate\Database\Eloquent\Relations\MorphTo;
1212
use Illuminate\Database\Eloquent\Relations\Relation;
13+
use Illuminate\Database\Query\Expression;
1314
use Yajra\DataTables\Exceptions\Exception;
1415

1516
/**
@@ -140,6 +141,19 @@ protected function isMorphRelation($relation)
140141
return $isMorph;
141142
}
142143

144+
protected function getColumnNameByIndex(int $index): string
145+
{
146+
$name = (isset($this->columns[$index]) && $this->columns[$index] != '*')
147+
? $this->columns[$index]
148+
: $this->getPrimaryKeyName();
149+
150+
if ($name instanceof Expression) {
151+
$name = $name->getValue($this->query->getGrammar());
152+
}
153+
154+
return in_array($name, $this->extraColumns, true) ? $this->getPrimaryKeyName() : $name;
155+
}
156+
143157
/**
144158
* Resolve the proper column name be used.
145159
*

src/QueryDataTable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,19 @@ protected function getColumnSearchKeyword(int $i, bool $raw = false): string
311311
return $this->setupKeyword($keyword);
312312
}
313313

314+
protected function getColumnNameByIndex(int $index): string
315+
{
316+
$name = (isset($this->columns[$index]) && $this->columns[$index] != '*')
317+
? $this->columns[$index]
318+
: $this->getPrimaryKeyName();
319+
320+
if ($name instanceof Expression) {
321+
$name = $name->getValue($this->query->getGrammar());
322+
}
323+
324+
return in_array($name, $this->extraColumns, true) ? $this->getPrimaryKeyName() : $name;
325+
}
326+
314327
/**
315328
* Apply filterColumn api search.
316329
*

0 commit comments

Comments
 (0)