Skip to content

Commit

Permalink
fix: fix search when prefix table is used (#3107)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 24, 2019
1 parent 7ea1bfe commit f546b58
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixes:

* Fix search when prefix table is used
* Fix storage page not being displayed if a contact does not exist anymore


Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public function search(Request $request)
return;
}

$results = SearchHelper::searchContacts($needle, 20, '`contacts`.`created_at`');
$results = SearchHelper::searchContacts($needle, 20, '`'.DB::connection()->getTablePrefix().'contacts`.`created_at`');

if (count($results) !== 0) {
return ContactResource::collection($results);
Expand Down
6 changes: 4 additions & 2 deletions app/Traits/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ public function scopeSearch(Builder $builder, $needle, $accountId, $limitPerPage

$builder->whereRaw("`$tablePrefix{$this->getTable()}`.`account_id` = $accountId AND ($queryString) $whereCondition");
$builder->orderByRaw($orderBy);

if ($sortOrder) {
$builder->sortedBy($sortOrder);
}
$builder->select(array_map(function ($column) use ($tablePrefix) {
return "$tablePrefix{$this->getTable()}.$column";

$builder->select(array_map(function ($column) {
return "{$this->getTable()}.$column";
}, $this->return_from_search));

return $builder->paginate($limitPerPage);
Expand Down

0 comments on commit f546b58

Please sign in to comment.