Hello everyone,
In my application users should have the possibility to favor certain pages. The user has received a “favorites list” in the yaml:
fields:
favorites:
type: pages
How can I add a page (via permalink) to this field? I have tried many things, but unfortunately none of them worked.
My last miserable attempt:
$user = $kirby->user();
$favorites= $user->favorites()->toPages();
$favorites->add(page('page://3hgC7B6br799ZJNC'));
$string = "";
foreach ($favorites as $page) {
$string .= "- " . $page->permalink();
if (!next($favorites)) {
$string .= "\n";
}
}
$user->favorites()->value($string);
Thank you very much for your help!
Best regards