Skip to content

Instantly share code, notes, and snippets.

@tabuna
Created October 1, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabuna/fa3f6573150ff17852a99731a059c219 to your computer and use it in GitHub Desktop.
Save tabuna/fa3f6573150ff17852a99731a059c219 to your computer and use it in GitHub Desktop.
SimpleSearchTrait
<?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