I am trying to update the user content file from the front end, specifically appendending to a structure field.
After looking at some solutions on the forum, I put this together in a controller:
<?php
return function ($kirby) {
$error = '';
if ($kirby->request()->is('POST') && get('unit')) {
try {
$kirby->impersonate('kirby');
if(get('unit') !== ''){
$submission = $kirby->user()->homework()->yaml();
$submission[] = [
'unitname' => 'The name of the unit',
'submission' => 'url',
'grade' => 'false'
];
$kirby->user()->update([
'homework' => Yaml::encode($submission)
], 'en');
$kirby->user()->update([
'homework' => Yaml::encode($submission)
], 'kr');
}
} catch (Exception $e) {
$error = error_message;
}
}
return [
'error' => $error
];
};
Unfourtunately this doesnt work and dont get any error messages. What am I missing. This user role does not have panel access but it still doesnt work if i grant access.