Created
May 17, 2023 10:33
-
-
Save zalviandyr/c0d00e46f51404db37790787cb1a4937 to your computer and use it in GitHub Desktop.
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
trait AutoSearch | |
{ | |
public function scopeAutoSearch(Builder $query, ?string $keyword) | |
{ | |
if ($keyword !== null) { | |
$dbDriver = DB::connection()->getConfig('driver'); | |
if ($dbDriver === 'pgsql') { | |
$columns = Arr::map($this->searchableColumns, fn ($elm) => $elm.'::text'); | |
$query->whereLike($columns, $keyword); | |
} else { | |
$query->whereLike($this->searchableColumns, $keyword); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment