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