src/Repositories/Criteria/UserSearchCriterion.php
<?php
namespace EscolaLms\Core\Repositories\Criteria;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
class UserSearchCriterion extends Criterion
{
public function __construct($value = null)
{
parent::__construct(null, $value);
}
public function apply(Builder $query): Builder
{
return $query->where(function ($q) {
$like = DB::connection()->getPdo()->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'pgsql' ? 'ILIKE' : 'LIKE';
$q->where('first_name', $like, "%$this->value%")
->orWhere('last_name', $like, "%$this->value%")
->orWhere('email', $like, "%$this->value%");
});
}
}