Hi Sonja,
thank you for your offer to take a closer look at the problem I described:
The problem occurs in Kirby versions 3.6 and 3.6.1.1. The affected site is running locally in my development environment under Laravel Valet.
The site is developed for a non-profit organization working in several European countries. Each country is divided into several regional areas. Each member of the organization/user of the site is assigned to a country and a region. This is done with corresponding fields for the users.
----
memberCountryGroupCode: DE
----
memberAreaCode: WST
Each member can perform one ore more functions in the country. These functions are assigned to the members/users via a tag field
----
memberCountryFunction: chief
There is one page per country, and one page per regional area. The pages for the regional areas are children of the pages for the countries.
The problem I described occurs in the template for the country pages. They should contain a table of the children regional areas which also contains the users with function in the areas.
In the page controller for the country page I create a collection of all users with function in the country:
$allChiefs = $kirby
->users()
->filterBy('memberStatus', '==', 'aktiv')
->filterBy('memberCountryGroupCode', '==', $page->countryCode())
->filterBy('memberCountryFunction', '==', 'chief');
Furthermore a collection of the children regional areas
$countryAreas = $page
->children()->listed()->sortBy('areaCode', 'asc');
In the template, I loop through the regional areas and display the users with function in the respective areas (for the example here only one function per area)
<?php foreach ($countryAreas as $area): ?>
<li>
<h2><?= $area->areaCode() ?></h2>
<?php $chief = allChiefs
->findBy('memberAreaCode', $area->areaCode()->value()); ?>
<?= $chief->memberLastName() ?>
</li>
<?php endforeach; ?>
Here, the error appears.
When I use
<?php if ($chief) {
echo $chief->memberLastName();
} ?>
the error disappears.