Laravel Airtable SDK
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_KEYcan be retrieved here: https://airtable.com/account
AIRTABLE_BASEcan be found here: https://airtable.com/api, select base then copy from URL:
https://airtable.com/[Base Is Here]/api/docs#curl/introduction
AIRTABLE_TABLEcan be found in the docs for the appropriate base, this is not case senstive. IE:
AIRTABLE_TYPECASTset 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
... 'tables' => [ 'default' => [ 'name' => env('AIRTABLE_TABLE', 'Main'), ], 'companies' => [ 'name' => env('AIRTABLE_COMPANY_TABLE', 'Companies'), ], ... ], ...
- This will only return the first 100 records due to Airtable page size limiation
- This will get all records by sending multiple requests until all record are fetched.
- Optional Parameter which is the delay between requests in microseconds as API is limited to 5 requests per second per base, defaults to 0.2 second.
Airtable::table('tasks')->all(); Airtable::table('tasks')->all(500000); // 0.5 seconds
- First argument is the column name
- Second argument is the operator or the value if you want to use equal '=' as an operator.
- Third argument is the value of the filter
Airtable::where('id', '5')->get(); Airtable::where('id', '>', '5')->get();
- First argument will be used for finding existing
- Second argument is additional data to save if no results are found and we are creating (will not be saved used if item already exists)
Airtable::firstOrCreate(['name' => 'myName'], ['field' => 'myField']);
- First argument will be used to find existing
- Second argument is additional data to save when we create or update
Airtable::updateOrCreate(['name' => 'myName'], ['field' => 'myField']); Airtable::table('companies')->firstOrCreate(['Company Name' => $team->name]);
- 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
Airtable::table('companies')->update('rec5N7fr8GhDtdNxx', [ 'name' => 'Google', 'country' => 'US']);
- First argument will be the id
- Second argument is the field you would like to update
Airtable::table('companies')->patch('rec5N7fr8GhDtdNxx', ['country' => 'US']);
- Array of data to be updated or patched
Airtable::table('companies')->patch([ [ 'id' => 'rec5N7fr8GhDtdNxx', 'fields' => ['country' => 'US'] ], [ 'id' => 'rec8BhDt4fs2', 'fields' => ['country' => 'UK'] ], ... ]);
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email firstname.lastname@example.org 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.