designtopack/public/site/plugins/notifications/user-methods/delete.php
2024-11-18 09:36:15 +01:00

22 lines
629 B
PHP

<?php
return function($notificationId) {
$user = kirby()->user();
try {
$notifications = $user->notifications()->isNotEmpty()
? Yaml::decode($user->notifications()->value())
: [];
foreach ($notifications as $key => $notification) {
if ($notification['id'] === $notificationId) {
unset($notifications[$key]);
}
}
$user->update([
'notifications' => Yaml::encode(array_values($notifications))
]);
} catch (\Throwable $th) {
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
}
};