How to access entity from EntityReferenceItem?
If entity in the foreach loop is not empty you should be able to do

$entity-&gt;field_name-&gt;entity
//or perhaps
$entity-&gt;field_name-&gt;referencedEntities();