Created
October 1, 2018 08:05
-
-
Save tabuna/fa3f6573150ff17852a99731a059c219 to your computer and use it in GitHub Desktop.
SimpleSearchTrait
This file contains hidden or 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
<?php | |
declare(strict_types=1); | |
namespace Orchid\Platform\Traits; | |
use Illuminate\Database\PostgresConnection; | |
trait SimpleSearchTrait | |
{ | |
/** | |
* @param $column | |
* @param null $query | |
* | |
* @return mixed | |
*/ | |
public function simpleSearchByColumn($column, $query = null) | |
{ | |
if (static::getQuery()->getConnection() instanceof PostgresConnection) { | |
return static::whereRaw("{$column}::TEXT ILIKE ?", "%{$query}%"); | |
} | |
return static::where($column, 'LIKE', "%{$query}%"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment