designtopack/public/site/plugins/notifications/user-methods/readAll.php
2024-11-18 13:45:40 +01:00

22 lines
No EOL
641 B
PHP

<?php
return function() {
try {
$notifications = $this->notifications()->isNotEmpty()
? Yaml::decode($this->notifications()->value())
: [];
$newNotification = null;
foreach ($notifications as $key => $notification) {
$notifications[$key]['isRead'] = true;
}
$updatedUser = $this->update([
'notifications' => Yaml::encode(array_values($notifications))
]);
return Yaml::decode($updatedUser->notifications()->value());
} catch (\Throwable $th) {
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
}
};