1 | <?php |
||
5 | class Airtable |
||
6 | { |
||
7 | private $api; |
||
8 | |||
9 | /** @var string */ |
||
10 | protected $base; |
||
11 | |||
12 | /** @var string */ |
||
13 | protected $table; |
||
14 | |||
15 | public function __construct($client, $table) |
||
20 | |||
21 | public function find(string $id) |
||
25 | |||
26 | public function create($data) |
||
30 | |||
31 | public function update(string $id, $data) |
||
35 | |||
36 | public function destroy(string $id) |
||
44 | |||
45 | public function all() |
||
49 | |||
50 | public function table($table) |
||
56 | |||
57 | public function where($column, $value) |
||
61 | |||
62 | public function firstOrCreate(array $idData, array $createData = []) |
||
81 | |||
82 | public function updateOrCreate(array $idData, array $updateData = []) |
||
83 | { |
||
84 | foreach ($idData as $key => $value) { |
||
85 | $this->where($key, $value); |
||
86 | } |
||
87 | |||
88 | $results = $this->get(); |
||
89 | |||
90 | // first |
||
91 | if ($results->isNotEmpty()) { |
||
92 | $item = $results->first(); |
||
93 | |||
94 | //update |
||
95 | return $this->update($item->id, $updateData); |
||
96 | } |
||
97 | |||
98 | // create |
||
99 | $data = array_merge($idData, $updateData); |
||
100 | |||
101 | return $this->create($data); |
||
102 | } |
||
103 | |||
104 | private function toCollection($object) |
||
108 | } |
||
109 |