2024-10-29 16:13:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
2024-11-22 07:53:43 +01:00
|
|
|
return function($notificationId) {
|
2024-10-29 16:13:07 +01:00
|
|
|
try {
|
2024-11-18 09:36:15 +01:00
|
|
|
$notifications = $this->notifications()->isNotEmpty()
|
|
|
|
|
? Yaml::decode($this->notifications()->value())
|
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
$newNotification = null;
|
|
|
|
|
foreach ($notifications as $key => $notification) {
|
2024-12-17 14:21:33 +01:00
|
|
|
if (!isset($notification['id'])) continue;
|
2024-11-18 09:36:15 +01:00
|
|
|
if ($notification['id'] === $notificationId) {
|
|
|
|
|
$notifications[$key]['isRead'] = true;
|
|
|
|
|
$newNotification = $notifications[$key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->update([
|
|
|
|
|
'notifications' => Yaml::encode(array_values($notifications))
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return $newNotification;
|
2024-10-29 16:13:07 +01:00
|
|
|
} catch (\Throwable $th) {
|
2024-11-18 09:36:15 +01:00
|
|
|
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
2024-10-29 16:13:07 +01:00
|
|
|
}
|
|
|
|
|
};
|