From 6014663a9fe4f94a86f7bbbbdef968de96accd9d Mon Sep 17 00:00:00 2001 From: imlonghao Date: Sun, 3 Jul 2022 11:01:38 +0800 Subject: [PATCH] model(home): refresh servers cache on due date changed --- app/Models/Home.php | 9 +++++++++ resources/views/servers/index.blade.php | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Models/Home.php b/app/Models/Home.php index f530cf4..14e56fe 100644 --- a/app/Models/Home.php +++ b/app/Models/Home.php @@ -92,6 +92,7 @@ class Home extends Model { $pricing = new Pricing(); $count = $altered_due_soon = 0; + $server_due_date_changed = false; foreach ($due_soon as $service) { if (Carbon::createFromFormat('Y-m-d', $service->next_due_date)->isPast()) { $months = $pricing->termAsMonths($service->term);//Get months for term to update the next due date to @@ -101,12 +102,20 @@ class Home extends Model ->update(['next_due_date' => $new_due_date]); $due_soon[$count]->next_due_date = $new_due_date;//Update array being sent to view $altered_due_soon = 1; + if ($service->service_type === 1) { + $server_due_date_changed = true; + Server::serverSpecificCacheForget($service->service_id); + } } else { break;//Break because if this date isnt past than the ones after it in the loop wont be either } $count++; } + if ($server_due_date_changed) { + Server::serverRelatedCacheForget(); + } + if ($altered_due_soon === 1) {//Made changes to due soon so re-write it Cache::put('due_soon', $due_soon); } diff --git a/resources/views/servers/index.blade.php b/resources/views/servers/index.blade.php index fd5bc36..bbac435 100644 --- a/resources/views/servers/index.blade.php +++ b/resources/views/servers/index.blade.php @@ -79,7 +79,7 @@ {{ $server->provider_name }} {{ $server->price }} {{$server->currency}} {{\App\Process::paymentTermIntToString($server->term)}} - {{now()->diffInDays(Carbon\Carbon::parse($server->next_due_date))}} + {{now()->diffInDays(Carbon\Carbon::parse($server->next_due_date), false)}} days {{ $server->owned_since }} @@ -187,7 +187,8 @@ @endforeach @else - No non-active servers found. + No non-active servers found. + @endif