A simple approach to interacting with Airtables.
You can install the package via composer:
composer require tapp/laravel-airtable
Publish the config file:
php artisan vendor:publish --provider="Tapp\Airtable\AirtableServiceProvider"
Define airtables account information in .env:
AIRTABLE_KEY=
AIRTABLE_BASE=
AIRTABLE_TABLE=
AIRTABLE_TYPECAST=false
AIRTABLE_KEY
Airtable is requiring personal access tokens for Authorization starting in 2024. A token can be created here: https://airtable.com/create/tokens. If you are upgrading from an API key to access token, simply replace the value previously held in this environment variable with your new token.AIRTABLE_BASE
can be found here: https://airtable.com/api, select base then copy from URL: https://airtable.com/[Base Is Here]/api/docs#curl/introduction
AIRTABLE_TABLE
can be found in the docs for the appropriate base, this is not case senstive. IE: tasks
AIRTABLE_TYPECAST
set this to true to allow automatic casting.If you need to support multiple tables, add them to the tables config in the config/airtable.php If your table is on a different base than the one set in the env, add that as well.
...
'tables' => [
'default' => [
'name' => env('AIRTABLE_TABLE', 'Main'),
'base' => 'base_id',
],
'companies' => [
'name' => env('AIRTABLE_COMPANY_TABLE', 'Companies'),
'base' => 'base_id',
],
...
],
...
use Airtable;
Airtable::table('tasks')->get();
Airtable::table('tasks')->all();
Airtable::table('tasks')->all(500000); // 0.5 seconds
Airtable::find('id_string');
Airtable::where('id', '5')->get();
Airtable::where('id', '>', '5')->get();
where
is not enough you may need to pass in raw filter values.Airtable::table('tasks')->filterByFormula('OR({id} = "abc", {id} = "def", {id} = "ghi")')->get();
asc
(default) or desc
Airtable::orderBy('id')->get();
Airtable::orderBy('created_at', 'desc')->get();
You can sort by multiple fields by calling orderBy
more than once (a single call with array syntax is not supported):
Airtable::orderBy('id')->orderBy('created_at', 'desc')->get();
Airtable::addParam('returnFieldsByFieldId', true); // one param at a time
Airtable::params(['returnFieldsByFieldId' => true, 'view' => 'My View']) // multiple params at once
Airtable::create(['name' => 'myName']);
Airtable::firstOrCreate(['name' => 'myName'], ['field' => 'myField']);
Airtable::updateOrCreate(['name' => 'myName'], ['field' => 'myField']);
Airtable::table('companies')->firstOrCreate(['Company Name' => $team->name]);
#### Update
- First argument will be the id
- Second argument is the whole record including the updated fields
**Note:** Update is destructive and clear all unspecified cell values if you did not provide a value for them. use PATCH up update specified fields
``` php
Airtable::table('companies')->update('rec5N7fr8GhDtdNxx', [ 'name' => 'Google', 'country' => 'US']);
Airtable::table('companies')->patch('rec5N7fr8GhDtdNxx', ['country' => 'US']);
Airtable::table('companies')->patch([
[
'id' => 'rec5N7fr8GhDtdNxx',
'fields' => ['country' => 'US']
],
[
'id' => 'rec8BhDt4fs2',
'fields' => ['country' => 'UK']
],
...
]);
Airtable::table('companies')->destroy('rec5N7fr8GhDtdNxx');
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email steve@tappnetwork.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.