[英]How to convert Collection of array of arrays to Eloquent style Collection of Objects of Objects in Laravel
我正在从 Airtable 中提取数据,返回如下:
Illuminate\Support\Collection {#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"
]
我可以找到如何转换为:
数组对象的集合,甚至
使用递归方法的 Collections of Collections 的集合,
但不是
对象集合(of Objects)
所以我可以像使用普通的 Eloquent 获取的结果一样访问$data->fields->name
类的数据
原来我可以使用 json 编码/解码将其全部转换为对象,然后收集它@
$things = Airtable::table('things')->all();
$things = json_decode(json_encode($things),FALSE);
$things = collect($things);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.