I have a list of products that are logged in a page field inside a structure field on the user’s account when purchased. I’m try to do a check on the product page to see if the product exists in the structure field of the user’s content file like this:
if($kirby->user()){
if ($kirby->user()->products()->toStrucure()->findBy('product', $page)) {
$purchased = true;
} else {
$purchased = false;
}
}
This doesn’t work though, $purchased
is true regardless.
I’m echoing the values like this check if they should be matching or not:
<?php
$purchases = $kirby->user()->products()->toStructure();
foreach($purchases as $purchase){
echo $purchase->product()->toPage();
};
echo $page;
?>
It and looks as though it should work as I intend. Where am I going wrong here?