我从关系中返回了一些数据作为集合:
$item = $this->detailedItems->where('detaileditem_product_id', $productId);
打印出来时,我可以看到我正在寻找的数据,但是在尝试访问它时:
$item->detaileditem_id;
或者
$item->detaileditem_name;
我收到一个错误:
例外:此集合实例上不存在属性 [detaileditem_id]。
我从关系中返回了一些数据作为集合:
$item = $this->detailedItems->where('detaileditem_product_id', $productId);
打印出来时,我可以看到我正在寻找的数据,但是在尝试访问它时:
$item->detaileditem_id;
或者
$item->detaileditem_name;
我收到一个错误:
例外:此集合实例上不存在属性 [detaileditem_id]。
where返回过滤后的集合,而不是单个项目。
如果您想要该集合的第一项符合您的条件,请先使用:
$item = $this->detailedItems->where('detaileditem_product_id', $productId)->first();