Skip to content

Commit

Permalink
fix error on search related wit (#606)
Browse files Browse the repository at this point in the history
Co-authored-by: Juan Moscoso <[email protected]>
  • Loading branch information
juanmoscoso-ch and juanmoscoso authored Oct 28, 2023
1 parent f8ba58f commit cfb4d80
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Http/Livewire/LivewireDatatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ public function defaultSort()
public function getSortString($dbtable)
{
$column = $this->freshColumns[$this->sort];

switch (true) {
case $column['sort']:
return $column['sort'];
Expand All @@ -730,6 +729,10 @@ public function getSortString($dbtable)
return Str::before($column['select'][0], ' AS ');
break;

case is_object($column['select']):
return Str::before($column['select']->getValue(DB::connection()->getQueryGrammar()), ' AS ');
break;

case $column['select']:
return Str::before($column['select'], ' AS ');
break;
Expand Down Expand Up @@ -1356,10 +1359,13 @@ public function addGlobalSearch()
foreach ($this->getColumnFilterStatement($i) as $column) {
$query->when(is_array($column), function ($query) use ($search, $column) {
foreach ($column as $col) {
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $col . ') like ?', '%' . mb_strtolower($search) . '%');
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column->getValue(DB::connection()->getQueryGrammar())), 'concat') ? '' : $this->tablePrefix) . $col . ') like ?', '%' . mb_strtolower($search) . '%');
}
}, function ($query) use ($search, $column) {
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $column . ') like ?', '%' . mb_strtolower($search) . '%');
$stringColumn = is_string($column)
? $column
: $column->getValue(DB::connection()->getQueryGrammar());
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($stringColumn), 'concat') ? '' : $this->tablePrefix) . $stringColumn . ') like ?', '%' . mb_strtolower($search) . '%');
});
}
});
Expand Down Expand Up @@ -1477,7 +1483,10 @@ public function addTextFilters()
$query->orWhere(function ($query) use ($index, $value) {
foreach ($this->getColumnFilterStatement($index) as $column) {
$column = is_array($column) ? $column[0] : $column;
$query->orWhereRaw('LOWER(' . $this->tablePrefix . $column . ') like ?', [mb_strtolower("%$value%")]);
$columnString = is_string($column)
? $column
: $column->getValue(DB::connection()->getQueryGrammar());
$query->orWhereRaw('LOWER(' . $this->tablePrefix . $columnString . ') like ?', [mb_strtolower("%$value%")]);
}
});
}
Expand Down

0 comments on commit cfb4d80

Please sign in to comment.