From 04896bf89a8675cafba4beedbc31b7e066575b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:43:59 +0300 Subject: [PATCH] delete report favorites --- app/Jobs/Common/DeleteReport.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/Jobs/Common/DeleteReport.php b/app/Jobs/Common/DeleteReport.php index 0a7c7c1ad..d66f8b89e 100644 --- a/app/Jobs/Common/DeleteReport.php +++ b/app/Jobs/Common/DeleteReport.php @@ -10,9 +10,37 @@ class DeleteReport extends Job implements ShouldDelete public function handle(): bool { \DB::transaction(function () { + $this->deleteFavorite(); + $this->model->delete(); }); return true; } + + public function deleteFavorite() + { + $favorites = setting('favorites.menu', []); + + if (empty($favorites)) { + return; + } + + foreach ($favorites as $user_id => $user_favorites) { + $user_favorites = json_decode($user_favorites, true); + + foreach ($user_favorites as $key => $favorite) { + if (! is_array($favorite['route'])) { + continue; + } + + if (str_contains($favorite['route'][0], 'reports.show') && $this->model->id == $favorite['route'][1]) { + unset($user_favorites[$key]); + } + } + + setting()->set('favorites.menu.' . $user_id, json_encode($user_favorites)); + setting()->save(); + } + } }