notifications()->isNotEmpty() ? Yaml::decode($this->notifications()->value()) : []; $notifications[] = $newNotification->toArray(); $this->update([ 'notifications' => $notifications ]); } public function deleteNotification($notificationId) { $notifications = $this->notifications()->isNotEmpty() ? Yaml::decode($this->notifications()->value()) : []; foreach ($notifications as $key => $notification) { if ($notification['id'] === $notificationId) { unset($notifications[$key]); } } $this->update([ 'notifications' => Yaml::encode(array_values($notifications)) ]); } }