I want to display on a .phtml file a list of order items for a logged in user. I don't want to use object manager.

I can get the id of the logged in user `($customerId)` on the `phtml`.

I have created a block class 

```
namespace 'moduleNameSpace';
class Orders extends \Magento\Framework\View\Element\Template
{
    protected $_customerSession;
    protected $_orderCollectionFactory;
    protected $orders;
    public function __construct(
            \Magento\Backend\Block\Template\Context $context,
            \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
            \Magento\Customer\Model\Session $customerSession,
             array $data = []
        ) {

    $this->_orderCollectionFactory = $orderCollectionFactory;

    parent::__construct($context, $data);
    $this->_customerSession = $customerSession;
}

public function getLoggedinCustomerId() {
    if ($this->_customerSession->isLoggedIn()) {
        return $this->_customerSession->getId();
    }
    return false;
}

public function getOrders($customerId)
{

    if (!$this->orders) {
        $this->orders = $this->_orderCollectionFactory->create()->addFieldToSelect(
            '*'
        )->addFieldToFilter(
            'customer_id',
            $customerId
        )->setOrder(
            'created_at',
            'desc'
        );
    }
    return $this->orders;
}
}

```

and then on the .phtml template i have

```
$customerId = $block->getLoggedinCustomerId();
$orders = $block->getOrders($customerId);
foreach ($orders as $order) {
foreach ($order->getAllVisibleItems() as $item){
   ...
}
}

```

The problem is that `foreach` is not working, even when I want to count the number of orders for example 

```
foreach ($orders as $order) {                                                                 
$orderCount++ ;
}
echo $orderCount;

```

How can I get all order items?
I think the problem may be on the block class