Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for advanced query syntax #13

Open
mmonkey opened this issue Aug 29, 2021 · 1 comment
Open

Add support for advanced query syntax #13

mmonkey opened this issue Aug 29, 2021 · 1 comment
Assignees

Comments

@mmonkey
Copy link
Collaborator

mmonkey commented Aug 29, 2021

Provide a method to pass in raw query strings.

@mmonkey mmonkey self-assigned this Aug 29, 2021
@JacobKnox
Copy link

The following code goes in ROOT\vendor\pokemon-tcg\pokemon-tcg-sdk-php\src\Resources\QueryableResource.php inside of the prepare method (replacing what should be roughly lines 65 - 73).

$queryParams = [];
if (!empty($this->query)) {
    $query = array_map(function ($attribute, $value) {
        if(is_array($value)){
            return $attribute . ':"' . implode('" ' . $value[0] . ' ' . $attribute . ':"', array_slice($value, 1)) . '"';
        }
        return $attribute . ':"' . $value . '"';
    }, array_keys($this->query), $this->query);

    $queryParams['q'] = implode(' ', $query);
    $this->query = [];
}

The user then passes in an array with the first value being "OR" or "AND" (i.e.: 'types' => ['OR', 'fire', 'water']).

A whole query would then look something like:
Pokemon::Card()->where(['types' => ['OR', 'fire', 'water'], 'subtypes' => 'mega'])->all();

NOTE: This is a rudimentary fix that should support basic OR/AND. I may add to this to work towards supporting more complex queries and/or direct queries.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants