如何在Laravel中将数组集合转换为Eloquent风格的对象集合



我正在从Airtable中提取数据,它返回如下:

IlluminateSupportCollection {#496 ▼
#items: array:11 [▼
0 => array:3 [▼
"id" => "rec4CaAx5EwGGi0I3"
"fields" => array:8 [▼
"description" => "Soft covers for switches"
"price" => 7
"tags" => array:2 [▼
0 => "recvPyxXM6GdIjgEr"
1 => "recvskfZPFMRPXzEb"
]

我可以找到如何转换为:

数组对象集合,甚至

集合集合集合使用递归方法,

但不是

对象的对象集合

所以我可以访问像$data->fields->name一样的数据,就像我可以访问正常的Eloquent提取结果一样

我可以使用json编码/解码将其全部转换为对象,然后在中收集

$things = Airtable::table('things')->all();
$things = json_decode(json_encode($things),FALSE);

$things = collect($things);

最新更新