diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 61074ff..d491b17 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -50,6 +50,13 @@ interface AdapterInterface */ public function filterByRelationship($query, Relationship $relationship, Closure $scope): void; + /** + * Manipulate the query to only include resources appropriate to given filter expression. + * + * @param string $expression The filter expression + */ + public function filterByExpression($query, string $expression): void; + /** * Manipulate the query to sort by the given attribute in the given direction. */ diff --git a/src/Adapter/EloquentAdapter.php b/src/Adapter/EloquentAdapter.php index 1f52921..7817914 100644 --- a/src/Adapter/EloquentAdapter.php +++ b/src/Adapter/EloquentAdapter.php @@ -61,6 +61,10 @@ class EloquentAdapter implements AdapterInterface $query->whereHas($this->getRelationshipProperty($relationship), $scope); } + public function filterByExpression($query, string $expression): void + { + } + public function sortByAttribute($query, Attribute $attribute, string $direction): void { $query->orderBy($this->getAttributeProperty($attribute), $direction); diff --git a/src/Adapter/NullAdapter.php b/src/Adapter/NullAdapter.php index bdd008c..499cc7d 100644 --- a/src/Adapter/NullAdapter.php +++ b/src/Adapter/NullAdapter.php @@ -27,6 +27,10 @@ class NullAdapter implements AdapterInterface { } + public function filterByExpression($query, string $expression): void + { + } + public function sortByAttribute($query, Attribute $attribute, string $direction): void { } diff --git a/src/ResourceType.php b/src/ResourceType.php index 131129d..ffe5315 100644 --- a/src/ResourceType.php +++ b/src/ResourceType.php @@ -122,6 +122,11 @@ final class ResourceType continue; } + if (is_int($name)) { + $this->adapter->filterByExpression($query, $value); + continue; + } + if ( isset($customFilters[$name]) && evaluate($customFilters[$name]->getVisible(), [$context])