从ManyToMany中获取最后一个值



我已经连接了两个表"状态";以及"服务";使用ManyToMany和我获得具有以下字段的所有条目:yield ArrayField::new('lastStatus', 'Last Status')

但我只想显示最后一个元素。我用end((尝试过,但它告诉我它不是数组。它是什么格式?我如何操作它?

它应该是DoctrineCommonCollectionsArrayCollection,并且可以使用last方法

感谢Arleigh Hix我找到了以下解决方案

# src/Entity/Service.php
public function getLastStatus()
{
return $this->getStatuses()->last();
}

yield TextField::new('lastStatus', 'Last Status')

最新更新