Skip to content

Commit cfb4d80

Browse files
fix error on search related wit (#606)
Co-authored-by: Juan Moscoso <[email protected]>
1 parent f8ba58f commit cfb4d80

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Http/Livewire/LivewireDatatable.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ public function defaultSort()
716716
public function getSortString($dbtable)
717717
{
718718
$column = $this->freshColumns[$this->sort];
719-
720719
switch (true) {
721720
case $column['sort']:
722721
return $column['sort'];
@@ -730,6 +729,10 @@ public function getSortString($dbtable)
730729
return Str::before($column['select'][0], ' AS ');
731730
break;
732731

732+
case is_object($column['select']):
733+
return Str::before($column['select']->getValue(DB::connection()->getQueryGrammar()), ' AS ');
734+
break;
735+
733736
case $column['select']:
734737
return Str::before($column['select'], ' AS ');
735738
break;
@@ -1356,10 +1359,13 @@ public function addGlobalSearch()
13561359
foreach ($this->getColumnFilterStatement($i) as $column) {
13571360
$query->when(is_array($column), function ($query) use ($search, $column) {
13581361
foreach ($column as $col) {
1359-
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $col . ') like ?', '%' . mb_strtolower($search) . '%');
1362+
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column->getValue(DB::connection()->getQueryGrammar())), 'concat') ? '' : $this->tablePrefix) . $col . ') like ?', '%' . mb_strtolower($search) . '%');
13601363
}
13611364
}, function ($query) use ($search, $column) {
1362-
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $column . ') like ?', '%' . mb_strtolower($search) . '%');
1365+
$stringColumn = is_string($column)
1366+
? $column
1367+
: $column->getValue(DB::connection()->getQueryGrammar());
1368+
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($stringColumn), 'concat') ? '' : $this->tablePrefix) . $stringColumn . ') like ?', '%' . mb_strtolower($search) . '%');
13631369
});
13641370
}
13651371
});
@@ -1477,7 +1483,10 @@ public function addTextFilters()
14771483
$query->orWhere(function ($query) use ($index, $value) {
14781484
foreach ($this->getColumnFilterStatement($index) as $column) {
14791485
$column = is_array($column) ? $column[0] : $column;
1480-
$query->orWhereRaw('LOWER(' . $this->tablePrefix . $column . ') like ?', [mb_strtolower("%$value%")]);
1486+
$columnString = is_string($column)
1487+
? $column
1488+
: $column->getValue(DB::connection()->getQueryGrammar());
1489+
$query->orWhereRaw('LOWER(' . $this->tablePrefix . $columnString . ') like ?', [mb_strtolower("%$value%")]);
14811490
}
14821491
});
14831492
}

0 commit comments

Comments
 (0)