Skip to content

Commit

Permalink
fix addGlobalSearch method (#511)
Browse files Browse the repository at this point in the history
Fix to prevent addGlobalSearch method to prepend tablePrefix when column contains '_concat_'.
It was generating a syntax error in the query, i.e.:
SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION **DBNAME**.**TABLEPREFIX**CONCAT_WS does not exist
  • Loading branch information
HobieCat authored Nov 27, 2022
1 parent 06d4a2a commit 8dc46a7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Http/Livewire/LivewireDatatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1320,10 +1320,10 @@ 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(' . $this->tablePrefix . $col . ') like ?', '%' . mb_strtolower($search) . '%');
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $col . ') like ?', '%' . mb_strtolower($search) . '%');
}
}, function ($query) use ($search, $column) {
$query->orWhereRaw('LOWER(' . $this->tablePrefix . $column . ') like ?', '%' . mb_strtolower($search) . '%');
$query->orWhereRaw('LOWER(' . (Str::contains(mb_strtolower($column), 'concat') ? '' : $this->tablePrefix) . $column . ') like ?', '%' . mb_strtolower($search) . '%');
});
}
});
Expand Down

0 comments on commit 8dc46a7

Please sign in to comment.