AirTable API client for Laravel. Used library [AirTable PHP)(https://github.com/lee-to/php-airtable)
The AirTable Client Laravel can be installed with Composer. Run this command:
composer require lee-to/laravel-airtable
php artisan vendor:publish --provider="AirTableLaravel\Providers\AirTableServiceProvider"
AIRTABLE_TOKEN=
AIRTABLE_BASE=
AIRTABLE_TABLE=
Add alias
'aliases' => [
...
'AirTable' => \AirTableLaravel\Facades\AirTableFacade::class,
],
Add provider
'providers' => [
...
AirTableLaravel\Providers\AirTableServiceProvider::class,
],
Get token and base from AirTable Account and AirTable API
use Airtable;
- List table records
Airtable::table('table_name')->get();
Or use default table
Airtable::get();
Or get all records
Airtable::all();
Airtable::table('table_name')->find('ID');
Or use default table
Airtable::find('ID');
- 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::table('table_name')->where("column", "operator", "value")->get();
- First argument is the column name
- Second argument is direction.
Airtable::table('table_name')->orderBy("column", "direction")->get();
- Only data for fields whose names are in this list will be included in the result. If you don't need every field, you can use this parameter to reduce the amount of data transferred
Airtable::table('table_name')->fields(["Column1", "Column2"])->get();
Or
Airtable::all(["Column1", "Column2"]);
- The maximum total number of records that will be returned in your requests. If this value is larger than pageSize (which is 100 by default), you may have to load multiple pages to reach this total.
Airtable::table('table_name')->limit(5)->get();
- Update one record
Airtable::table('table_name')->update('ID', ["Column1" => "Value"]);
OR
foreach(Airtable::get() as $record) {
$record->update(["Column1" => "Value"]);
}
- Update or create record
Airtable::table('table_name')->updateOrCreate('ID', ["Column1" => "Value"]);
- Create a new record
Airtable::table('table_name')->create(["Column1" => "Value"]);
- Create a new record or find first match
Airtable::table('table_name')->firstOrCreate(["Column1" => "Value"]);
- Delete one record
Airtable::table('table_name')->delete('ID');
OR
foreach(Airtable::table('table_name')->get() as $record) {
$deleted = $record->delete();
$deleted->isDeleted(); // Check is deleted or not
}
foreach(Airtable::table('table_name')->get() as $record) {
$record->getId(); // ID
$record->COLUMN1; // Any fields in table
}
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.
If you have found a security issue, please contact the maintainers directly at leetodev@ya.ru.