From 7deb78f57448e6d94534645b68461840466a6d9c Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 29 Jan 2026 10:29:05 +0530 Subject: [PATCH] Added auto deletion logic - record created 6 months ago --- app/Models/GuardPatrolEntry.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Models/GuardPatrolEntry.php b/app/Models/GuardPatrolEntry.php index 6d47357..b240685 100644 --- a/app/Models/GuardPatrolEntry.php +++ b/app/Models/GuardPatrolEntry.php @@ -2,12 +2,15 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; class GuardPatrolEntry extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ @@ -27,13 +30,24 @@ class GuardPatrolEntry extends Model public function guardNames(): BelongsTo { - //return $this->belongsTo(CheckPointName::class); + // return $this->belongsTo(CheckPointName::class); return $this->belongsTo(GuardName::class, 'guard_name_id'); } public function checkPointNames(): BelongsTo { - //return $this->belongsTo(CheckPointName::class); + // return $this->belongsTo(CheckPointName::class); return $this->belongsTo(CheckPointName::class, 'check_point_name_id'); } + + public function prunable(): Builder + { + // // Start of two months ago (first day of that month) + // $startOfTwoMonthsAgo = now()->subMonthsNoOverflow(6)->startOfMonth(); + // // End of previous month (last day of last month) + // $endOfPrevMonth = now()->subMonthNoOverflow()->endOfMonth(); + + // return static::whereBetween('created_at', [$startOfTwoMonthsAgo, $endOfPrevMonth]); + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } }