-
app/Models/Filters/AdminServerFilter.php
Open in GitHubuse BadMethodCallException; use Spatie\QueryBuilder\Filters\Filter; use Illuminate\Database\Eloquent\Builder; class AdminServerFilter implements Filter { public function __invoke(Builder $query, $value, string $property) { if ($query->getQuery()->from !== 'servers') { throw new BadMethodCallException('Cannot use the AdminServerFilter against a non-server model.'); } $query ->select('servers.*') ->leftJoin('users', 'users.id', '=', 'servers.owner_id') ->where(function (Builder $builder) use ($value) { $builder->where('servers.uuid', $value) ->orWhere('servers.uuid', 'LIKE', "$value%") ->orWhere('servers.uuidShort', $value) ->orWhere('servers.external_id', $value) ->orWhereRaw('LOWER(users.username) LIKE ?', ["%$value%"]) ->orWhereRaw('LOWER(users.email) LIKE ?', ["$value%"]) ->orWhereRaw('LOWER(servers.name) LIKE ?', ["%$value%"]); }) ->groupBy('servers.id'); } }