Skip to content

Add filter by formula functionality #70

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ Airtable::where('id', '5')->get();
Airtable::where('id', '>', '5')->get();
```

### Filter records by formula
- When using `where` is not enough you may need to pass in raw filter values.
- [Airtable reference](https://support.airtable.com/docs/formula-field-reference)
``` php
Airtable::table('tasks')->filterByFormula('OR({id} = "abc", {id} = "def", {id} = "ghi")')->get();
```

#### Sorting records

- First argument is the column name
Expand Down
7 changes: 7 additions & 0 deletions src/Airtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public function where($column, $operator, $value = null)
return $this;
}

public function filterByFormula($formula)
{
$this->api->addFilterByFormula($formula);

return $this;
}

public function orderBy(string $column, string $direction = 'asc')
{
$this->api->addSort($column, $direction);
Expand Down
7 changes: 7 additions & 0 deletions src/Api/AirtableApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public function addFilter($column, $operation, $value): AirtableApiClient
return $this;
}

public function addFilterByFormula(string $formula): AirtableApiClient
{
$this->filters[] = $formula;

return $this;
}

public function addSort(string $column, string $direction = 'asc'): AirtableApiClient
{
if ($direction === 'desc') {
Expand Down