-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search both columns in journal instead of fuzzy search - too many jou…
…rnals for Fuzzy
- Loading branch information
1 parent
76f78d0
commit 4736f9b
Showing
5 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Filters; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Support\Arr; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
|
||
class MultiColumnFilter implements Filter | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $columns; | ||
|
||
public function __construct(...$columns) | ||
{ | ||
$this->columns = $columns; | ||
} | ||
|
||
public function __invoke(Builder $query, $value, string $property) | ||
{ | ||
$attributes = $this->columns; | ||
|
||
// is database engine postgresql? if so, use ILIKE as it is case insensitive | ||
$like = config('database.default') === 'pgsql' ? 'ILIKE' : 'LIKE'; | ||
|
||
$query->where(function (Builder $query) use ($attributes, $value, $like) { | ||
foreach (Arr::wrap($attributes) as $attribute) { | ||
$query->orWhere(function ($query) use ($attribute, $value, $like) { | ||
$query->orWhere($attribute, $like, "%{$value}%"); | ||
}); | ||
} | ||
}); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters