tapp/laravel-airtable
Composer 安装命令:
composer require tapp/laravel-airtable
包简介
Laravel Airtable SDK
README 文档
README
A simple approach to interacting with Airtables.
Installation
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_KEYAirtable 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_BASEcan be found here: https://airtable.com/api, select base then copy from URL:https://airtable.com/[Base Is Here]/api/docs#curl/introductionAIRTABLE_TABLEcan be found in the docs for the appropriate base, this is not case senstive. IE:tasksAIRTABLE_TYPECASTset this to true to allow automatic casting.
Example Config
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',
],
...
],
...
Usage
Import the facade in your class.
use Airtable;
Get records from that table
- This will only return the first 100 records due to Airtable page size limiation
Airtable::table('tasks')->get();
Get all records from that table.
- 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
Get one record from the default table.
Airtable::find('id_string');
Filter records
- 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();
Filter records by formula
- When using
whereis not enough you may need to pass in raw filter values. - Airtable reference
Airtable::table('tasks')->filterByFormula('OR({id} = "abc", {id} = "def", {id} = "ghi")')->get();
Sorting records
- First argument is the column name
- Second argument is the sort direction:
asc(default) ordesc
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();
Set other API Parameters
Airtable::addParam('returnFieldsByFieldId', true); // one param at a time Airtable::params(['returnFieldsByFieldId' => true, 'view' => 'My View']) // multiple params at once
Create
- Insert a record
Airtable::create(['name' => 'myName']);
First or Create
- 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']);
Update or Create
- 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]);
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
Airtable::table('companies')->update('rec5N7fr8GhDtdNxx', [ 'name' => 'Google', 'country' => 'US']);
Patch
- First argument will be the id
- Second argument is the field you would like to update
Airtable::table('companies')->patch('rec5N7fr8GhDtdNxx', ['country' => 'US']);
Mass Update or Patch
- Array of data to be updated or patched
Airtable::table('companies')->patch([ [ 'id' => 'rec5N7fr8GhDtdNxx', 'fields' => ['country' => 'US'] ], [ 'id' => 'rec8BhDt4fs2', 'fields' => ['country' => 'UK'] ], ... ]);
Destroy
- Destroy a record
Airtable::table('companies')->destroy('rec5N7fr8GhDtdNxx');
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email steve@tappnetwork.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
tapp/laravel-airtable 适用场景与选型建议
tapp/laravel-airtable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 257.63k 次下载、GitHub Stars 达 112, 最近一次更新时间为 2019 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「airtable」 「tapp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tapp/laravel-airtable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tapp/laravel-airtable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tapp/laravel-airtable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a Filament resource and a policy for Spatie Webhook client
Filament Laravel Survey plugin.
Manipulate Airtable API using PHP
PHP SDK for Bands In Town API
Multipart Uploads using Laravel, AWS S3, and Uppy
Invite users to slack group
统计信息
- 总下载量: 257.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 113
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-22