lee-to/laravel-airtable

AirTable API client for Laravel

v1.1 2020-07-24 09:27 UTC

This package is auto-updated.

Last update: 2024-10-29 05:53:41 UTC


README

AirTable API client for Laravel. Used library [AirTable PHP)(https://github.com/lee-to/php-airtable)

Installation

The AirTable Client Laravel can be installed with Composer. Run this command:

composer require lee-to/laravel-airtable

Publish provider

php artisan vendor:publish --provider="AirTableLaravel\Providers\AirTableServiceProvider"

.env:

AIRTABLE_TOKEN=
AIRTABLE_BASE=
AIRTABLE_TABLE=

config/app.php:

Add alias

'aliases' => [
        ...
        
        'AirTable' => \AirTableLaravel\Facades\AirTableFacade::class,
    ],

Add provider

'providers' => [

        ...

        AirTableLaravel\Providers\AirTableServiceProvider::class,
    ],

Usage

Get token and base from AirTable Account and AirTable API

Import.

use Airtable;

Get records from that table

  • List table records
Airtable::table('table_name')->get();

Or use default table

Airtable::get();

Or get all records

Airtable::all();

Get one record from table.

Airtable::table('table_name')->find('ID');

Or use default table

Airtable::find('ID');

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::table('table_name')->where("column", "operator", "value")->get();

Sort records

  • First argument is the column name
  • Second argument is direction.
Airtable::table('table_name')->orderBy("column", "direction")->get();

Fields

  • 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"]);

Max records

  • 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

  • Update one record
Airtable::table('table_name')->update('ID', ["Column1" => "Value"]);

OR

foreach(Airtable::get() as $record) {
    $record->update(["Column1" => "Value"]);
}

Update or create

  • Update or create record
Airtable::table('table_name')->updateOrCreate('ID', ["Column1" => "Value"]);

Create

  • Create a new record
Airtable::table('table_name')->create(["Column1" => "Value"]);

First or create

  • Create a new record or find first match
Airtable::table('table_name')->firstOrCreate(["Column1" => "Value"]);

Delete

  • 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
}

Get fields of record

foreach(Airtable::table('table_name')->get() as $record) {
    $record->getId(); // ID 
    
    $record->COLUMN1; // Any fields in table 
}

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Security

If you have found a security issue, please contact the maintainers directly at leetodev@ya.ru.