From ae4e7d0239e505efab4794469815bd17d3790c70 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 29 Jan 2026 10:49:13 +0530 Subject: [PATCH] Added auto deletion logic - record created 6 months ago --- app/Models/WeightValidation.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Models/WeightValidation.php b/app/Models/WeightValidation.php index 3ae09e0..a475d60 100644 --- a/app/Models/WeightValidation.php +++ b/app/Models/WeightValidation.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 WeightValidation extends Model { + use Prunable; use SoftDeletes; protected $fillable = [ @@ -33,4 +36,13 @@ class WeightValidation extends Model { return $this->belongsTo(Item::class); } + + public function prunable(): Builder + { + // $startOfTwoMonthsAgo = now()->subMonthsNoOverflow(3)->startOfMonth(); + // $endOfPrevMonth = now()->subMonthNoOverflow()->endOfMonth(); + + // return static::whereBetween('created_at', [$startOfTwoMonthsAgo, $endOfPrevMonth]); + return static::where('created_at', '<=', now()->subMonthsNoOverflow(6)); + } }